微信小程序如何修改指定的json数据?

tab: [

  {
    imgSrc: "/images/tab-xl.png",
    tit: "销量",
    postId: 0
  },
  {
    imgSrc: "/images/tab-jg.png",
    tit: "价格",
    postId: 1
  },
  {
    imgSrc: "/images/tab-rq1.png",
    tit: "人气",
    postId: 2
  },
  {
    imgSrc: "/images/tab-zx.png",
    tit: "新品",
    postId: 3
  }
]

如题,我有一组数据!
例如我想修改tab[2]中的imgSrc中的value
重点:如何通过微信小程序中的setData方法来修改指定的value?
阅读 6.8k
1 个回答

data:

ab: [
  {
    imgSrc: "/images/tab-xl.png",
    tit: "销量",
    postId: 0
  },
  {
    imgSrc: "/images/tab-jg.png",
    tit: "价格",
    postId: 1
  },
  {
    imgSrc: "/images/tab-rq1.png",
    tit: "人气",
    postId: 2
  },
  {
    imgSrc: "/images/tab-zx.png",
    tit: "新品",
    postId: 3
  }
]

修改:

let ab = this.data.ab
ab[2].imgSrc = "/images/test.png"
this.setData({ab})
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题