怎么把多层数组中的值取出来,赋值给data里面的变量?

小程序 文章 2021-03-18 09:21 560 0 全屏看文

AI助手支持GPT4.0

怎么把多层数组中的值取出来,赋值给data里面的变量?How to take out the value in the multi-level array and assign it to the variable in data?

怎么把多层数组中的值取出来,赋值给data里面的变量?

假设我现在有一个数组text,里面还是数组,怎么把最里面的一个值拿出来,赋值给别的变量。如:

text{

{name,id}

{name,id}

{name,id}

}

data{

newid,

text

}

怎么样把text中的id,赋值给data中的newid


Suppose I have an array text, which is still an array. How can I get the innermost value and assign it to another variable. For example: text {name, ID} {name, ID} {name, ID}} data {newid, text} how to assign the ID in text to the newid in data

回答:

卢霄霄:

let text = this.data.text

let item = text[text.length - 1]

if(item) {

this.setData({newid: item.id})

}


张有釜:

this.setData({newid:text[i].id})

i是text数组的键

张杰 ༽ Mark:
不知道你是不是这个意思~text:[      {name: '大王', id: 1},      {name: '小王', id: 2},      ]data:{      newid:'',      text:''}------this.setData({  newid:text[1].id})

-EOF-

AI助手支持GPT4.0