下面是Thiem Nguyen解决方案扩展Select域的一般实现。希望它会节省一些时间;)
/**
* Adds an additional option to a select field filled by a store
* @cfg {mixed} valueFieldValue Value of the added option
* @cfg {string} displayFieldValue Text to display for the added option
*/
Ext.define('util.field.SelectPlus', {
extend: 'Ext.field.Select',
xtype: 'selectfieldplus',
alternateClassName: 'Ext.field.SelectPlus',
requires: 'Ext.data.Store',
config: {
displayFieldValue: '',
valueFieldValue: ''
},
/**@override
* Insert our item each time the store is loaded
* @param {Ext.data.Store} store The refreshed store
*/
onStoreDataChanged: function(store) {
if(store.findExact(this.getValueField(), this.getValueFieldValue()) === -1) { //prevent infinite loop ;)
var item = Ext.create(store.getModel());
item.set(this.getValueField(), this.getValueFieldValue());
item.set(this.getDisplayField(), this.getDisplayFieldValue());
store.insert(0, item);
}
this.callParent([store]);
}
});
谢谢,第二个解决方案,你的意思是添加一个条目,我有每个商店?有没有办法将这样的条目自动添加到所有商店?由于我的商店是从本地存储加载的,我可以在加载代理后添加这个“假”条目吗? – borck 2012-04-12 16:22:24
你可以通过听'负载'事件 – 2012-04-12 16:45:24
自动添加!谢谢... – borck 2012-04-12 18:06:41