[英]Sencha Touch list and scrollToRecord
I have a long sencha touch list and I am trying desperately to scroll that list into somewhere in the middle on startup. 我的Sencha触摸列表很长,我拼命尝试在启动时将该列表滚动到中间的某个位置。
The function 功能
btnScroll:function() {
var list = Ext.getCmp("myList");
var position = 4;
list.scrollToRecord(list.getStore().getAt(position));
}
works if I tap the button: scrollBtn.setHandler(btnScroll);
如果我点击按钮,则可以工作:
scrollBtn.setHandler(btnScroll);
, but it does not work in ,但不适用于
MyList.constructor:function() {
...
this.callParent();
this.btnScroll();
}
It just fails without error message. 它只是失败而没有错误消息。 Same goes if I do it in the calling function:
如果在调用函数中执行同样的操作:
btnOpenList:function() {
var list = new MyList();
list.show();
list.btnScroll();
}
It works sometimes(!) if I use setTimeout(this.btnScroll,70);
如果我使用
setTimeout(this.btnScroll,70);
它有时会起作用(! setTimeout(this.btnScroll,70);
instead, but never if I use setTimeout(this.btnScroll,50);
相反,但是如果我使用
setTimeout(this.btnScroll,50);
or setTimeout(this.btnScroll,120);
或
setTimeout(this.btnScroll,120);
I think it happens because the list elements are not rendered/positioned. 我认为发生这种情况是因为列表元素未呈现/定位。 But I did not find any afterrender event.
但是我没有发现任何后退事件。
So how would I define a scroll position in which the list should start? 那么,如何定义列表应从其开始的滚动位置?
You could do it in painted event. 您可以在彩绘事件中做到这一点。 just add to your list or to container that contains all components that u need to bind the painted event.. and then get your list there and add event to btn.. or whatever you want.. by the template:
只需将其添加到包含绑定绘画事件所需的所有组件的列表或容器中,然后在列表中将事件添加到btn ..或模板所需的任何内容即可。
element.clearListeners();
element.addListener('tap',function(){
//...
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.