小程序怎么在setData方法中,给一个对象赋值一个数组指定下标的字段?

小程序 文章 2021-12-14 09:40 569 0 全屏看文

AI助手支持GPT4.0

小程序怎么在setData方法中,给一个对象赋值一个数组指定下标的字段?How can a small program assign an object to an array with a specified subscript field in the setData method?

小程序怎么在setData方法中,给一个对象赋值一个数组指定下标的字段?

小程序怎么在setData方法中,给一个对象赋值一个数组指定下标的字段?

How does the applet assign an array to an object and specify the subscript field in the SetData method?

回答:

Lv: Max Human:

所以你不应该先贴你的代码?

微喵网络:
let index=1this.setData({  ['a['+index+']']: 1})
dreamhunter:

全部读出来,改动,整体setdata

鲤子:

上码

六娃:想把数组的字段 赋值给objone这个变量应该怎么做?
松岗:

Object.keys 可以获取数组下标

let a = ['apple', 'banner']Object.keys(a) // ['0', '1']
ZZ:

this.data.obj.key = arr[index]

this.setData({

obj: this.data.obj

})

武曲心:

你的问题有点读不懂,下面列举两种,x是对象变量名,y是x属性名,z是数组,index是z下标

1、this.setData({ 'x.y':z[index] })

2、let obj = x;x[index] = z[index];this.setData({ x:obj })

garField:
const index = 3;const updateKey = `arr[${index}]`;this.setData({  [updateKey]:"newValue",})
六娃:我是自己创建了一个对象,想把数组其中一个下标的字段的值,赋值给这个对象

-EOF-

AI助手支持GPT4.0