onLoad:function(options){
let num = this.data.num;
wx.getStorage({
key: 'orderList',
success: function(res){
// success
console.log('已选美食',res.data)
},
fail: function() {
// fail
},
complete: function() {
// complete
}
})
var orderList = wx.getStorageSync('orderList');
var list=orderList.list;
//console.log(list)
//object 转 array
var order = JSON.parse(options.order);
var t_order = [];
var t_total = 0;
for(var k in order){
if(order[k].num > 0){
t_order.push(order[k]);
t_total = t_total + order[k].cost*order[k].num; //计算总价格
}
}
t_total=order.total;
this.setData({
total: t_total,
orderList:list
});
console.log('数量list',list)
num = list.length;
console.log('数量num',num)
},
打印出结果是下图
1、如何得到list的个数 num = list.length;这个得到结果是undefined
2、如何得到list的id,就是这个1,2,3 这个值是上一个页面传过来的选择值,是选择后的值,不是固定1,2,3,list也可能{3:2,5:1,13:2}
想要得到list数组中的个数,和id
num = 3
listid1 = 1 ,listid2 = 2,listid3 = 3,
如果list是{3:2,5:1,13:2};listid1 = 3 ,listid2 = 4,listid3 = 13
大神们帮忙看下
你打印的list是对象不是数组,自然没有list.length,t_total是什么意思?循环里面做了计算,反手就是被order.total赋值,num可以用Object.keys(list).length
这个是个对象啊,对象是没有length属性的
num 的问题解决了,
listid1 = 1 ,listid2 = 2,listid3 = 3, 如果list是{3:2,5:1,13:2};listid1 = 3 ,listid2 = 4,listid3 = 13
这个,还是不会,获取。帮忙看下