这是 vue.js 中的计算属性:shopCart() { var scart = [], group, node; scart.push({ payMethod: 0, transactionReference: "", RoomNumber: 0, addressId: 0, deliveryMinutes: 0, comment: "", posList: [], }); for (var x = 0; x < this.items.length; x++) { group = this.items[x].selectedOptions; scart[0].posList.push({ articleId: this.items[x].id, quantity: this.items[x].quantity, singlePrice: this.items[x].price, variantList: [], parent: true, name: this.items[x].name, }); for (var y = 0; y < group.length; y++) { node = group[y].options; for (var z = 0; z < node.length; z++) { scart[0].posList[0].variantList += node[z].id + ","; } } } scart = scart.map(function (e) { return JSON.stringify(e); }); scart = scart.join(","); return scart; },它写入以下对象:{ "payMethod": 0, "transactionReference": "", "RoomNumber": 0, "addressId": 0, "deliveryMinutes": 0, "comment": "", "posList": [ { "articleId": 20001, "quantity": 1, "singlePrice": 8.99, "variantList": "2001,4001,5001,2003,4003,", "parent": true, "name": "Fisch Filet" }, { "articleId": 20002, "quantity": 1, "singlePrice": 8.99, "variantList": "", "parent": true, "name": "Cheese Burger" } ]}我需要这个:{ "payMethod": 0, "transactionReference": "", "RoomNumber": 0, "addressId": 0, "deliveryMinutes": 0, "comment": "", "posList": [ { "articleId": 20001, "quantity": 1, "singlePrice": 8.99, "variantList": "2001,4001,5001,", "parent": true, "name": "Fisch Filet" },最后一个嵌套循环仅将我的字符串写入第一次出现的“variantList”中。我似乎无法找到正确的方法来解决上一个循环中“variantList”的出现问题。任何人都可以指出我正确的方向吗?
查看完整描述