收藏
回答

这是什么情况!

问题模块 框架类型 问题类型 操作系统 工具版本
开发者工具 小程序 Bug Windows v1.02.1902010

- 当前 Bug 的表现(可附上截图)


- 预期表现

数组setData更新数据会覆盖前面元素

- 复现路径

setData

- 提供一个最简复现 Demo

setData内容{"listData[0]":{"id":0,"code":"pdtid","text":"产品编号:","type":"text","value":"","isdisplay":true},"listData[0].id":0,"listData[0].value":"w11111-1","listData[1]":{"id":0,"code":"pdtname","text":"产品名称:","type":"text","value":"","isdisplay":true},"listData[1].id":0,"listData[1].value":"产品1-1","listData[2]":{"id":0,"code":"anticode","text":"溯源码:","type":"number","value":"","isdisplay":false},"listData[2].id":0,"listData[3]":{"id":0,"code":"remark","text":"异常备注:","type":"text","value":"","isdisplay":false},"listData[3].id":0,"listData[4]":{"id":0,"code":"pdtid","text":"产品编号:","type":"text","value":"","isdisplay":true},"listData[4].id":1,"listData[4].value":"w11111-2","listData[5]":{"id":0,"code":"pdtname","text":"产品名称:","type":"text","value":"","isdisplay":true},"listData[5].id":1,"listData[5].value":"产品1-2","listData[6]":{"id":0,"code":"anticode","text":"溯源码:","type":"number","value":"","isdisplay":false},"listData[6].id":1,"listData[7]":{"id":0,"code":"remark","text":"异常备注:","type":"text","value":"","isdisplay":false},"listData[7].id":1}
pdtadd.js? [sm]:170 listData的值[{"id":1,"code":"pdtid","text":"产品编号:","type":"text","value":"w11111-2","isdisplay":true},{"id":1,"code":"pdtname","text":"产品名称:","type":"text","value":"产品1-2","isdisplay":true},{"id":1,"code":"anticode","text":"溯源码:","type":"number","value":"","isdisplay":false},{"id":1,"code":"remark","text":"异常备注:","type":"text","value":"","isdisplay":false},{"id":1,"code":"pdtid","text":"产品编号:","type":"text","value":"w11111-2","isdisplay":true},{"id":1,"code":"pdtname","text":"产品名称:","type":"text","value":"产品1-2","isdisplay":true},{"id":1,"code":"anticode","text":"溯源码:","type":"number","value":"","isdisplay":false},{"id":1,"code":"remark","text":"异常备注:","type":"text","value":"","isdisplay":false}]


console.log("setData内容" + JSON.stringify(param));

this.setData(param);

console.log("listData的值" + JSON.stringify(that.data.listData));


最后一次编辑于  02-15
回答关注问题邀请回答
收藏

5 个回答

  • 黎😄
    黎😄
    02-15

    请把问题描述清楚。

    1. 你想要干嘛?

    2. 出现了什么问题?

    02-15
    赞同 2
    回复 2
    • 游海洋19937936251
      游海洋19937936251
      02-15

       data: {

         arr:[],

       },

       onLoad: function (options) {

         this.setData({"arr[0].id":0})

         this.setData({"arr[1].id":1})

       },


      得到的结果是 第一个和第二个元素的id都是1


      02-15
      回复
    • 瑕不掩瑜
      瑕不掩瑜
      02-16

      建议setData能省着用就尽量省

      02-16
      回复
  • 铭锋科技
    铭锋科技
    02-15

    相当的复杂啊

    02-15
    赞同 1
    回复
  • 来一间
    来一间
    02-19

    浅拷贝的数据拿不到

    02-19
    赞同
    回复
  • 彩云衣内容电商平台
    彩云衣内容电商平台
    02-18

    let arr=this.data.arr;

    arr[0].id"=0;

    arr[1].id=1;

    this.setData({arr:arr})

    浅拷贝的数据拿不到


    02-18
    赞同
    回复
  • 游海洋19937936251
    游海洋19937936251
    02-16

    问题已搞定,浅拷贝的问题。

    02-16
    赞同
    回复