Only digits (0-9) can be put inside [] in the path string: sbData["车间二"]["un00201-1"].state;at socketTask.onmessage callback function Error: Only digits (0-9) can be put inside [] in the path string: sbData["车间二"]["un00201-1"].state
Only digits (0-9) can be put inside [] in the path string: sbData["车间二"]["un00201-1"].state;at socketTask.onmessage callback function Error: Only digits (0-9) can be put inside [] in the path string: sbData["车间二"]["un00201-1"].state
this.setData({ [`sbData.${key}.${eRep.deviceName + '-' + eRep.equipmentId}.state`]: 0 }); this.setData({ [`sbData.${key}.${eRep.deviceName}-${eRep.equipmentId}.state`]: 0 });
两种写法都可以。
如果 key 不是数字,也就是说不是在设置数组,得用点 "." 拼起来。
如果在设置数组的某一项,用方括号 []
let sbData = `sbData[${key}][${eRep.deviceName}-${eRep.equipmentId}].state`; this.setData({ [sbData]: 0 });
尝试一下这样写
Error: Only digits (0-9) can be put inside [] in the path string: sbData["车间二"]["un00201-1"].state
this.setData({ [`sbData[${变量}][${变量}].state`] : 0 })
Error: Only digits (0-9) can be put inside [] in the path string: sbData["车间二"]["un00201-1"].state
this.setData({
[`sbData.${变量}.${变量}.state`] : 0
})
sbData:{ "车间一":{ "un00101":{ "name":"1号", "state":1 }, "un00102":{ "name":"2号", "state":1 }, "un00103":{ "name":"2号", "state":1 }, "un00104":{ "name":"2号", "state":1 }, "un00105":{ "name":"2号", "state":1 }, } } this.setData({ sbData[变量][变量].state : 0 })