![](https://i-blog.csdnimg.cn/blog_migrate/61a37cb842cfce7ec95a0bdd343b8c4a.jpeg)
2020-10-30_5f9bd80e5cf82.jpeg
- 定义一个空数组 userList
/**
* Page initial data
*/
data: {
userList: []
},
- 在 onLoad 中进行数组追加元素
/**
* Lifecycle function--Called when page load
*/
onLoad: function (options) {
var that = this
var list = []
for (var i = 0; i < 3; i++) {
var obj = {
jobnumber: '00'+i,
department:'技术部门',
salary:'20k'
}
list.push(obj)
}
this.setData({
userList:list
})
console.log(this.data.userList)
},
- 查看打印信息
![](https://i-blog.csdnimg.cn/blog_migrate/242bbd0a1fc32d1fe9601ae2b315eede.png)
image.png