如何在Sencha Touch列表视图的列表视图中获得“在底部滚动”和“在顶部滚动”?

时间:2013-09-12 11:17:30

标签: extjs sencha-touch sencha-architect

我想为列表视图编写lazy loading代码,以便我需要为用户向下滚动到列表底部并向上滚动到列表顶部时触发的控制器添加操作。 / p>

我怎样才能使用Sencha Architect?

1 个答案:

答案 0 :(得分:2)

我不使用Architect,但您需要的是在控制器中获取列表的引用,并在列表的scroll事件中附加滚动器对象的initialize事件的处理程序:

<强>控制器

config: {
    refs: {
        list: '...',
        ...
    },
    control: {
        list: {
            initialize: 'onListInit'
        },
        ...
    },
    ...
},
onListInit: function() {
    var scroller = this.getScrollable().getScroller();
    scroller.on('scrollstart', this.onNnListScrollStart, this);
    scroller.on('scrollend',   this.onNnListScrollEnd,   this);
},
onNnListScrollStart: function(scroller, x, y) {
    console.log('START SCROLL');
},

onNnListScrollEnd: function(scroller, x, y) {
    console.log('scroll x:'+x);
    console.log('scroll y:'+y);

    var bottom = scroller.maxPosition.y;
    var top    = scroller.minPosition.y;

    var isScrollUp   = scroller.dragDirection.y === -1;
    var isScrollDown = scroller.dragDirection.y === 1;

    if (bottom === y && isScrollDown) {
        console.log('BOTTOM');    
    }

    if (top === y && isScrollUp) {
        console.log('TOP');
    }

    console.log('END SCROLL');
},
...

可以下载实施本指南的Sencha Architect示例项目here