微信小程序用setData修改數組或對象中的一個屬性值,超好用,最簡單的實現方法,不容錯過!大神們 都 在 看 的方法!!!

在page中this

 data: {
 2     info:[
 3       {
 4         name:"yuki",
 5         tou:"../img/head.jpg",
 6         zGong:130,
 7         gMoney:222222
 8       },
 9       {
10         name: "yuki",
11         tou: "../img/head.jpg",
12         zGong: 130,
13         gMoney:222222
14       },
15       {
16         name: "yuki",
17         tou: "../img/head.jpg",
18         zGong: 130,
19         gMoney:222222
20       },
21       {
22         name: "yuki",
23         tou: "../img/head.jpg",
24         zGong: 130,
25         gMoney:222222
26       },
27       {
28         name: "yuki",
29         tou: "../img/head.jpg",
30         zGong: 130,
31         gMoney:222222
32       }
33     ]
34   }

 

 

onLoad: function () {
      var that=this;
      var up = "info[" + 0 + "].gMoney";//先用一個變量,把(info[0].gMoney)用字符串拼接起來
      that.setData({
        [up]:1
      })
  }
相關文章
相關標籤/搜索