Javascript 检查属性数量是否为>;1然后推送价格*数量
下面的函数循环遍历Javascript 检查属性数量是否为>;1然后推送价格*数量,javascript,arrays,google-tag-manager,Javascript,Arrays,Google Tag Manager,下面的函数循环遍历var input中对象的属性,例如 [{ name: 'Nagellack 15 ml 2 2', id: '1057290002', price: '1.9', brand: 'a.o.n.', quantity: 1 }, { name: 'Ceramic Nail Lacquer 6 ml Coral Reef Coral Reef', id: '1027410001', price: '6.9',
var input
中对象的属性,例如
[{
name: 'Nagellack 15 ml 2 2',
id: '1057290002',
price: '1.9',
brand: 'a.o.n.',
quantity: 1
}, {
name: 'Ceramic Nail Lacquer 6 ml Coral Reef Coral Reef',
id: '1027410001',
price: '6.9',
brand: 'Artdeco',
quantity: 1
}]
并将新对象推入
products_list []
我试图设置一个条件,检查对象的数量是否大于1,然后将价格乘以数量。这里的问题是,我只得到一种产品的价格,尽管有两种产品的数量
我不知道在代码中设置条件的最佳位置
function() {
var input = {{dl_purchase_products}};
var products_list = [];
for(i=0;i<input.length;i++){
products_list.push({
id: input[i].id.slice(0,6),
price: input[i].price, <---- this should be the price for 2
quantity: input[i].quantity
});
}
return products_list;
}
function(){
var输入={dl_购买_产品};
var产品清单=[];
对于(i=0;i将价格乘以数量。如此复杂的描述是如此简单的解决方案。有点尴尬:)谢谢你的帮助!@Scott Hunter