求大神瞄一眼,关于block循环的一个问题(代码,日志,效果图都有)
发布于 6 年前 作者 linjie 9928 次浏览 来自 问答

wxml代码

<view class='xztz-items'>
       <scroll-view class='scroll-H' scroll-x="true" style='width:100%'>
        <block wx:for='{{items}}' wx:for-index='index' wx:for-item='item'>
            <view class='yuan' hover-class='yuan-hover'>
              <view class='yuan-1'>{{item.top}}</view>
              <view class='yuan-2'>{{item.center}}</view>
              <view class='yuan-3'>{{item.deep}}</view>
            </view>
        </block>
      </scroll-view>
      <text class='xztz-other iconfont icon-jiahao' bindtap='onPush'></text>
    </view>

data: {

    items:[{
      top:'(1)',
      center:'A',
      deep:'护理'
    }, {
        top: '(2)',
        center: 'B',
        deep: '护理'
      }, {
        top: '(3)',
        center: 'C',
        deep: '护理'
      },]
  },

js代码

onPush:function(){
   let obj = {
     top: '(4)',
     center: 'D',
     deep: '测试'
   }
   this.data.items.push(obj)
   console.log('items',this.data.items)
 }

我想实现的功能就是,点击一下加号

就往数组里push一个数据

然后触发block去加载

但是我的数据已经push进去了

但是block还是使用的push之前的数据

我怎么触发block去重新加载新数组里的数据呢???

请大神赐教,不胜感激

3 回复

看你写的真难受,先把js学好吧

onPush: function() {

let obj = {

top: ‘(4)’,

center: ‘D’,

deep: ‘测试’

}

this.data.items.push(obj)

this.setData({

items: this.data.items

})

console.log(‘items’, this.data.items)

},

我这样写的不对呀…是哪里写的不对呢…

回到顶部