鍍金池/ 問答/HTML/ 微信小程序怎么實現(xiàn)局部刷新?

微信小程序怎么實現(xiàn)局部刷新?

我把評論放在一個list里,我想要實現(xiàn)點擊提交評論的時候新提交的內(nèi)容會出現(xiàn)在評論區(qū)

回答
編輯回答
尕筱澄

ajax提交,然后dom添加相應(yīng)的html

2017年12月16日 10:10
編輯回答
涼薄

js

page({
    data:{
      commitdata:[{user:"haha",content:"yo"},{user:"haha2",content:"yo2"}]
    }
    getData:function(){
        let that = this;
        wx.request({
            url:"xx.xx.xx",
            success:function(data){
                this.setData({commitdata:data});
            }
        })
    },
    commitData:function(){ //點擊提交數(shù)據(jù)
      let that = this;
        wx.request({
            url:"xx.xx.xx",
            success:function(data){ 
                this.setData({commitdata:that.commitdata.push(data)});
            }
        })
    }

})

wxml

<view wx:for="{commitdata}">{content}</view>

簡單的寫了下 大概就是這個樣子 提交后的數(shù)據(jù)push到原來的數(shù)據(jù)上面就行

2017年1月14日 11:27
編輯回答
局外人

獲取目前l(fā)ist內(nèi)容和新增評論的內(nèi)容,然后用concat的方法將評論內(nèi)容加入到list里,最后setData。

2017年6月24日 10:15