问题
I am using sencha list in my application. It is a scrollable list. I want to scroll the list by up, down key and hand gesture in keyboard. Does anyone know how to do it?
Please help me.
This is my code:
{
xtype: 'list',
pinHeaders: false,
variableHeights: false,
itemTpl:
'<div>' +
'<div>{name}</div>' +
'</div>',
store: 'myStore',
grouped: true,
onItemDisclosure: true
}
回答1:
Check out this fiddle https://fiddle.sencha.com/#fiddle/53t
You can add a document eventlistener on keydown event in your application launch function and then scroll by the height of your list item.
Ext.application({
name: 'Fiddle',
launch: function() {
Ext.Viewport.add({
xtype: 'slidelist'
});
document.addEventListener("keydown", Ext.bind(onBackKeyDown, this), false);
function onBackKeyDown(e) {
switch(e.keyIdentifier)
{
case "Up":
Ext.ComponentQuery.query('slidelist')[0].getScrollable().getScroller().scrollBy(0, -47);
break;
case "Down":
Ext.ComponentQuery.query('slidelist')[0].getScrollable().getScroller().scrollBy(0, 47);
break;
default:
break;
}
}
}
});
来源:https://stackoverflow.com/questions/21154398/sencha-list-scrolling-with-keyboard