weex
weex copied to clipboard
list loadmore callback not work
i have a list which register onloadmore event:
<list onloadmore="loadMore" loadmoreoffset="50">
<cell repeat="{{newsList}}" index="{{$index}}">
<item title={{title}} image={{images[0]}}></item>
</cell>
</list>
methods:{
loadMore: function(){
var self = this;
...
stream.sendHttp({method:'GET',url:url},function(ret){
var retData = JSON.parse(ret);
var newItems = retData.xxx;
for(item in newItems){
self.aaaa.push(item);
}
self.currentPage++;
});
},
when i scroll to the end of list,onloadmore event triggered successfully,and i push new date to the data source array. but the new data does not bind to the list.
did i miss sth??
@Jinjiang @MrRaindrop
This demo should work:
<template>
<list onloadmore="loadMore" loadmoreoffset="50">
<cell class="cell" repeat="{{newsList}}" index="{{$index}}">
<item title={{title}}><text>{{$index}} : {{title}}</text></item>
</cell>
</list>
</template>
<style>
.cell {
height: 300px;
}
</style>
<script>
module.exports = {
data: {
newsList: [{
title: 'a'
}, {
title: 'b'
}, {
title: 'c'
}, {
title: 'd'
}, {
title: 'e'
}]
},
methods: {
loadMore: function () {
this.newsList.push({
title: 'Hello , this is the new-loaded one!'
})
}
}
}
</script>
You can simplify your code to a working scale like this demo, then add your code and logic gradually to see when to break.
Oh , stupid...js for in statement is not like foreach in java.
just change my code to this:
for(index in newItems){
self.aaaa.push(newItems[index]);
}
so sorry to disturb you