当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 微信小程序js数组中插入“新数据对象”,数据对象中插入“新属性”

微信小程序js数组中插入“新数据对象”,数据对象中插入“新属性”

2020年07月17日  | 移动技术网IT编程  | 我要评论

动态添加数据对象或数据对象中的属性


动态添加数据对象

此处展示的是自己之前写的一个分页功能中,动态添加数据对象到已有的数组中。

var tmpArr = that.data.tickets;
tmpArr.push.apply(tmpArr, res.data.data); //追加的方式和之前加载的对象数据连接在一起
that.setData({
	tickets: tmpArr
})

动态添加数据对象中的属性

添加islike的新属性到list[’+index+’] 里面,变成 [‘list[’+index+’].islike’]。

that.setData({
	['list['+index+'].islike']: true//注意左边的路径需要添加到['']里,index需要['+index+']自动识别为数字
})
console.log(that.data.list[index].islike)//打印测试

本文地址:https://blog.csdn.net/weixin_44703147/article/details/107357583

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网