如果启用了 FocusManager,则通过菜单标题隐藏网格列会导致位置哈希发生变化。如果未启用 FocusManager,则不会发生这种情况。我尝试覆盖 Ext.menu.Item onClick 以停止事件,但这不起作用,因为看起来浏览器单击事件无法访问,因为 EventManager 正在包装侦听器并将其替换为 EventObject 焦点事件。
这是示例代码(也在http://jsfiddle.net/jacobg/8X3qw/)。您可以查看位置哈希更改的控制台日志,并尝试将 FocusManager.enable 注释掉和取消注释:
window.onhashchange = function () {
console.log('hash changed to: ' + location.hash);
};
Ext.define('Company', {
extend: 'Ext.data.Model',
fields: [
{name: 'company'},
{name: 'price', type: 'float', convert: null, defaultValue: undefined},
{name: 'change', type: 'float', convert: null, defaultValue: undefined},
{name: 'pctChange', type: 'float', convert: null, defaultValue: undefined},
{name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia', defaultValue: undefined}
],
idProperty: 'company'
});
Ext.onReady(function() {
//Ext.FocusManager.enable();
// sample static data for the store
var myData = [
['3m Co', 71.72, 0.02, 0.03, '9/1 12:00am'],
['Alcoa Inc', 29.01, 0.42, 1.47, '9/1 12:00am'],
['Altria Group Inc', 83.81, 0.28, 0.34, '9/1 12:00am']
];
// create the data store
var store = Ext.create('Ext.data.ArrayStore', {
model: 'Company',
data: myData
});
// create the Grid
var grid = Ext.create('Ext.grid.Panel', {
renderTo: Ext.getBody(),
store: store,
columns: [
{
text : 'Company',
flex : 75,
sortable : false,
dataIndex: 'company'
},
{
text : 'Price',
width : 50,
sortable : true,
renderer : 'usMoney',
dataIndex: 'price'
},
{
text : 'Change',
width : 50,
sortable : true,
dataIndex: 'change'
}
],
height: 200,
width: 400,
title: 'Array Grid'
});
});