我有一个语法问题,我试图将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
请帮我。
最佳答案
您需要在文字数组之外构建basket数组: