简体   繁体   English

在Sencha Touch中按需加载NestedList的项目

[英]Load items on demand for NestedList in Sencha Touch

I am building an email-like app with Sencha Touch, and I use NestedList widget for the navigation panel. 我正在使用Sencha Touch构建类似于电子邮件的应用程序,并且将NestedList小部件用于导航面板。

  • inbox 收件箱
    • mail1 邮件1
    • mail2 邮件2
    • mail3 邮件3
  • outbox 发件箱

There are maybe many mails in the inbox, so I want to load it on demand, when user scroll to the end of the list, it will load next 10 items automatically and append new items to the list. 收件箱中可能有很多邮件,因此我想按需加载,当用户滚动到列表的末尾时,它将自动加载下10个项目并将新项目追加到列表中。

How can I achieve this ? 我该如何实现?

You could try something like the following: 您可以尝试以下操作:

var loadingItems = false;

var fetchItems = function () {
    //fetch new items to add
    loadingItems = false;
};

//nestedList: reference to the nestedList
//x: new x position
//y: new y position
var scrollListener = function(nestedList, x, y) {
    //set some boundary for where we should start loading data
    var screenBottom = nestedList.getHeight() - OFFSET; 

    //if we're within some region near the bottom of the list...
    if((y >= screenBottom) && !loadingItems) {
        loadingItems = true;
        fetchItems();
    }
};
nestedList.addListener("move", scrollListener);

Since Sencha Touch shares alot of code with ExtJS you might get an idea of how to achieve this by looking at the various liveGrid implementations in ExtJS since that is basically what you are creating. 由于Sencha Touch与ExtJS共享了大量代码,因此您可以通过查看ExtJS中的各种liveGrid实现来了解如何实现此目的,因为这基本上就是您要创建的。

This is the most stable and comprehensive livegrid i've used: http://www.ext-livegrid.com/ 这是我使用过的最稳定,最全面的livegrid: http : //www.ext-livegrid.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM