weex icon indicating copy to clipboard operation
weex copied to clipboard

list loadmore callback not work

Open Rowandjj opened this issue 10 years ago • 3 comments

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??

Rowandjj avatar Jun 15 '16 06:06 Rowandjj

@Jinjiang @MrRaindrop

jinyue-rdj avatar Jun 15 '16 06:06 jinyue-rdj

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.

MrRaindrop avatar Jun 15 '16 06:06 MrRaindrop

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

Rowandjj avatar Jun 15 '16 06:06 Rowandjj