账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    Angular4 reduce 价格累加报错
    34
    0

    麻烦帮忙看一下

    报错信息:

    谷歌Chrome:
    
    Error TypeError: Cannot read property 'reduce' of  undefined
    at checkAndUpdateView(core.es5.js:12241)
    
    
    火狐Firefox:
    
    TypeError: this.shoppingcartList is undefined
    MallShoppingCartComponent.prototype.getTotal@http://localhost:4200/0.chunk.js:1408:9

    ============================

    代码片段(shopingcartList 就是返回的数据列表):

    public shoppingcarList: any;
    
    ngOnInit(){
    this.getMockTest();
    }
    
    getMockTest(){
    this.ishoppingcarApi.getLIstUsingGET().subscribe(
      result => {
        this.shopingcartList =result;
        ... ...
    }
    
    
    getTotal(){        // 价格累加
    return this.shoppingcartList.reduce((state, order) =>{
     return order.cartCommodities.reduce((state,courseList => {
    return state + (courseList.checked ? courseList.price ? courseList.price.presentPrice : 0);
    }, state);
    
    }, 0);
    }
    
    
    html 模板中
    {{getTotal()}}
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 湘邵顽童 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部