如何向数组中的对象中添加值
发布于 6 年前 作者 shenmin 2786 次浏览 来自 问答

已知:

  1. js文件中的data中有空数组 array[]

  2. 最终的数组array的样式如下所示:

    array[

    {name1:value,describe:[{key1:value1,key2:value2,...,key3:value3},{key1:value1,key2:value2,...,key3:value3},...{key1:value1,key2:value2,...,key3:value3}]},

    {name2:value,describe:[{key1:value1,key2:value2,...,key3:value3},{key1:value1,key2:value2,...,key3:value3},...{key1:value1,key2:value2,...,key3:value3}]},

    ...

    {nameN:value,describe:[{key1:value1,key2:value2,...,key3:value3},{key1:value1,key2:value2,...,key3:value3},...{key1:value1,key2:value2,...,key3:value3}]}

    ]

3.数组1->对象1->数组2->对象2的结构,在数组2中添加对象2

  • 希望提供的能力
  1. 如何向array中添加describe:[];

  2. 添加完describe:[]后如何添加各obeject,即{key1:value1,key2:value2,...,key3:value3}

  3. 如何在数组2中添加对象2

1 回复

你好,先通过this.data.array取出值,进行修改再通过this.setData赋值就可以啦

回到顶部