【发布时间】:2016-09-15 07:45:59
【问题描述】:
我有一个语法问题,我正在尝试将 go.pl 分析集成到 shopify 中的购物车,因此最终代码将如下所示:
var goadservicesq = goadservicesq || [];
goadservicesq.push(
[
"_BASKET",
[
// first position in basket
{
identifier: '35353635535',
quantity: '2'
},
// second position in basket
{
identifier: '55353533378566',
quantity: '1'
},
// last position in basket
{
identifier: '458457435643464',
quantity: '3'
},
// extra product which solves the "comma" problem
{}
]
]
);
在这里,我试图在内部创建“for”循环以获得类似上面的最终结果:
// trying to make "for" loop
$.getJSON( "/cart.js", function( data ) {
console.log(data);
// user.go.pl CART script
var goadservicesq = goadservicesq || [];
goadservicesq.push(
[
"_BASKET",
[
for (var i = 0; i < data.items_count; i++) {
{
identifier: data.items[i].id,
quantity: data.items[i].quantity
},
}
// extra product which solves the "comma" problem
{}
]
]
);
});
它会抛出一个错误 -> http://prntscr.com/ci7jpz 请帮帮我。
【问题讨论】:
标签: javascript arrays loops shopify