Vuejs, get the problem of cyclic accumulation of values in an object

carts=["goods_list": {
    "charm": [
                    {
                        "shop": "charm",
                        "id": 51,
                        "url": "https://img.codeshelper.com/upload/img/2021/03/13/vmysyvuzy418081.jpg_400x400.jpg",
                        "name": "2018",
                        "price": "169.00",
                        "quantity": 1,
                        "attr": ":2XL :",
                        "cn_base_ship": "10.00",
                        "rec_type": 0,
                        "remark": null,
                        "img": "https://img.codeshelper.com/upload/img/2021/03/13/vmysyvuzy418081.jpg_400x400.jpg",
                        "is_fba": 0,
                        "sn": "TAOBAO_565168354699",
                        "goods_total": "169.00",
                        "checked": false
                    },
                    {
                        "shop": "charm",
                        "id": 52,
                        "url": "https://img.codeshelper.com/upload/img/2021/03/13/vmysyvuzy418081.jpg_400x400.jpg",
                        "name": "2018",
                        "price": "169.00",
                        "quantity": 1,
                        "attr": ":2XL :",
                        "cn_base_ship": "10.00",
                        "rec_type": 0,
                        "remark": null,
                        "img": "https://img.codeshelper.com/upload/img/2021/03/13/vmysyvuzy418081.jpg_400x400.jpg",
                        "is_fba": 0,
                        "sn": "TAOBAO_565168354699",
                        "goods_total": "169.00",
                        "checked": false
                    }
                    ],
    "": [
                            {
                                "shop": "",
                                "id": 53,
                                "url": "https://img.codeshelper.com/upload/img/2021/03/13/4ni5ree1kyt8082.jpg",
                                "name": "28270",
                                "price": "2.90",
                                "quantity": 1,
                                "attr": "None",
                                "cn_base_ship": "10.00",
                                "rec_type": 0,
                                "remark": null,
                                "img": "https://img.codeshelper.com/upload/img/2021/03/13/4ni5ree1kyt8082.jpg",
                                "is_fba": 0,
                                "sn": "1688_562251109331?scm=1007.17269.96789.0",
                                "goods_total": "2.90",
                                "checked": false
                            }
                            ]
                        }]
        calcTotalmoney: function () {
            var self = this;
            var totalMoney =  0;
            this.carts.forEach(function (item) {
                item.forEach(function (g) {
                    self.totalMoney += g.price * g.quantity;
                });
            });
        }
the error message is carts.forEach is not function

come up with the cyclic cumulative unit price * quantity. Thank you

Mar.13,2021

goods_list is an object attribute and should be placed in an object (carts should be an object) to make the expression correct.


first of all, your outermost layer should be curly braces


calcTotalmoney: function () {
            var self = this;
            this.totalMoney= 0;
            var num =0.00;
            for (var index in this.carts) {
                this.carts[index].forEach(function (g) {
                   num += parseFloat(g.price * g.quantity);
                });
            }
            return num;
        },
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b40b31-2c54c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b40b31-2c54c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?