使用
scrollIntoView
:
Ext.application({
name: 'Fiddle',
launch: function () {
// The data store containing the list of states
var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data: [{
"abbr": "section1",
"name": "Section-1"
}, {
"abbr": "section2",
"name": "Section-2"
}, {
"abbr": "section3",
"name": "Section-3"
}, {
"abbr": "section4",
"name": "Section-4"
}, {
"abbr": "section5",
"name": "Section-5"
}, {
"abbr": "section6",
"name": "Section-6"
}, {
"abbr": "section7",
"name": "Section-7"
}]
});
// Create the combo box, attached to the states data store
Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose Section',
store: states,
queryMode: 'local',
displayField: 'name',
valueField: 'abbr',
renderTo: Ext.getBody(),
listeners: {
change: function(field, v) {
var toScroll = filterPanel.getComponent(v);
var s = filterPanel.getScrollable();
s.scrollIntoView(toScroll.el);
}
}
});
var filterPanel = Ext.create('Ext.panel.Panel', {
bodyPadding: 5, // Don't want content to crunch against the borders
width: 300,
height: 400,
autoScroll: true,
title: 'Sections',
items: Array(7).fill(null).map((_, i) => ({
xtype: 'panel',
height: 100,
itemId: 'section' + (i + 1),
html: 'Section' + (i + 1),
style: {
borderColor: 'black',
borderStyle: 'solid',
},
})),
renderTo: Ext.getBody()
});
}
});