由于列表渲染需要给指定二维数组的二级数组删除和追加元素,JS代码如下,提示错误,麻烦各位老师给指正,谢谢!
arr={name[‘simon’,‘dd’,…],date[‘1998’,‘2005’,…]}
//删除最后一个选项
btn_xx_del(e) {
del_id = e.currentTarget.id //获取被点击组件id
arr[del_id].name.pop()
this.setData({
arr: arr
})
},
错误提示:Cannot read property 'name' of undefined; [Component] Event Handler Error @ pages/xmfq1/xmfq#bound btn_xx_del
TypeError: Cannot read property 'name' of undefined
//增加一个选项
btn_xx_add(e) {
var aa = { name: [''] }
del_id = e.currentTarget.id //获取被点击组件id
arr[del_id].push(aa)
this.setData({
arr: arr
})
},
错误提示:Cannot read property 'push' of undefined