收藏
回答

这是什么情况!

框架类型 问题类型 操作系统 工具版本
小程序 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));


回答关注问题邀请回答
收藏

5 个回答

  • 黎😄
    黎😄
    2019-02-15

    请把问题描述清楚。

    1. 你想要干嘛?

    2. 出现了什么问题?

    2019-02-15
    有用 2
    回复 2
    • 洋
      2019-02-15

       data: {

         arr:[],

       },

       onLoad: function (options) {

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

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

       },


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


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

      建议setData能省着用就尽量省

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

    相当的复杂啊

    2019-02-15
    有用 1
    回复
  • 来一间
    来一间
    2019-02-19

    浅拷贝的数据拿不到

    2019-02-19
    有用
    回复
  • 轻兔小程序服务商
    轻兔小程序服务商
    2019-02-18

    let arr=this.data.arr;

    arr[0].id"=0;

    arr[1].id=1;

    this.setData({arr:arr})

    浅拷贝的数据拿不到


    2019-02-18
    有用
    回复
  • 洋
    2019-02-16

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

    2019-02-16
    有用
    回复
登录 后发表内容