在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 微信小程序中,怎樣在點(diǎn)擊按鈕后,修改setData里面的數(shù)值?

微信小程序中,怎樣在點(diǎn)擊按鈕后,修改setData里面的數(shù)值?

圖片描述

圖片描述

圖片描述

如上圖:這是通過wx.request從后臺請求回來的數(shù)據(jù),數(shù)據(jù)里面有一個(gè)TabContentStatus,默認(rèn)狀態(tài)是false,我需要給每一個(gè)選項(xiàng)設(shè)置一個(gè)按鈕,讓點(diǎn)擊按鈕的時(shí)候,這個(gè)值變成true,應(yīng)該怎么設(shè)置? 求打救~ 謝謝

回答
編輯回答
痞性

在你的onPostTabList函數(shù)里:

onPostTabList: function(e) {
    //獲取所有的數(shù)據(jù)
    var TabSelectedValue_key = this.data.TabSelectedValue_key
    
    //獲取你綁定在view上的數(shù)據(jù)
    var tablistid = e.currentTarget.dataset.tablistid
    
    //遍歷數(shù)據(jù),找到對應(yīng)的tablistid=catalogId,將其TabContentStatus設(shè)為true
    for(var i=0, len=TabSelectedValue_key.length; i<len; i++) {
        var item = TabSelectedValue_key[i]
        
        if(item.catalogId==tablistid) {
            item.TabContentStatus = true
            
            //賦予改變后的數(shù)據(jù)
            TabSelectedValue_key[i] = item
            
            break
        }
    }
    
    //設(shè)置改變后的數(shù)據(jù)
    this.setData({
        TabSelectedValue_key:TabSelectedValue_key
    })
}
2017年6月8日 20:36
編輯回答
尐飯團(tuán)

渲染數(shù)據(jù)的時(shí)候可以綁定一個(gè)data-index="{{index}}"

onPostTabList: function(e){
    var index = e.currentTarget.dataset.index;//獲取點(diǎn)擊的索引
    var arr = this.data.TabSelectedValue_key; //獲取數(shù)組
    arr[index].TabContentStatus = true; 
    this.setData({ //更新數(shù)據(jù)
        TabSelectedValue_key: arr
    })
}

恩,應(yīng)該是這樣的:)

2017年10月10日 01:24