微信小程序:setData({})方法

Page({

  data: {

    text: 'init data',

    num: 0,

    array: [{text: 'init data'}],

    object: {

      text: 'init data'    

       }

  },

  changeText: function() {

    // this.data.text = 'changed data'  // bad, it can not work

   this.setData({

      text: 'changed data'    })

  },

  changeNum: function() {

    this.data.num =1this.setData({

      num: this.data.num

    })

  },

  changeItemInArray: function() {

    // you can use this way to modify a danamic data path

    this.setData({

      'array[0].text':'changed data'    })

  },

  changeItemInObject: function(){

    this.setData({

      'object.text':'changed data'    });

  },

  addNewField: function() {

    this.setData({

      'newField.text':'new data'    })

  }

})

你可能感兴趣的:(微信小程序:setData({})方法)