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> |
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去重新加载新数组里的数据呢???
请大神赐教,不胜感激

看你写的真难受,先把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)
},
看一下setData的文档吧,直接赋值不会重新渲染页面的
谢谢,已解决
就是setData方法的原因
后来我用push方法还是不行
网上找了个帖子说是用concat方法
试了一下,解决了
这个你可以看下push和concat的返回值
setData