Page.PRototype.setData()
setData函數(shù)用于將數(shù)據(jù)從邏輯層發(fā)送到視圖層,同時改變對應的this.data的值。注意:
直接修改 this.data 無效,無法改變頁面的狀態(tài),還會造成數(shù)據(jù)不一致。單次設置的數(shù)據(jù)不能超過1024kB,請盡量避免一次設置過多的數(shù)據(jù)。setData() 參數(shù)格式
接受一個對象,以 key,value 的形式表示將 this.data 中的 key 對應的值改變成 value。
其中 key 可以非常靈活,以數(shù)據(jù)路徑的形式給出,如
array[2].message,a.b.c.d,并且不需要在 this.data 中預先定義。Page({ data: { text: 'init data', 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' }) }
新聞熱點
疑難解答