标签:微信 not field class change 不一致 blog set mod
一般setData方法多用于点击后改变页面信息或者刷新后与后台交互获取最新的信息
注意:
方法如下:
js:
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 = 1 this.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‘ }) } })
wxml:
<view>{{text}}</view> <button bindtap="changeText"> Change normal data </button> <view>{{num}}</view> <button bindtap="changeNum"> Change normal num </button> <view>{{array[0].text}}</view> <button bindtap="changeItemInArray"> Change Array data </button> <view>{{object.text}}</view> <button bindtap="changeItemInObject"> Change Object data </button> <view>{{newField.text}}</view> <button bindtap="addNewField"> Add new data </button>
标签:微信 not field class change 不一致 blog set mod
原文地址:http://www.cnblogs.com/strong-FE/p/7117945.html