我正在为组合框构建一个“修复”,因为当您打开行编辑器时,它会在文本框中显示值字段而不是显示字段。但是,要做到这一点,我必须在发送到服务器之前更改组合框的值。为此,我的想法是挂钩到行编辑插件的 beforeedit 事件。
最大的问题是我无法找到一种方法来访问我正在编辑行的网格,或者直接使用行编辑插件。
我唯一能找到的是组合框所在的形式,combobox.up('form')
我可以挂钩这些事件,但我认为它们不会“足够早”发生。但是,我找不到从表单中获取行编辑插件的方法:\
关于如何解决这个问题的任何想法?
编辑1:
根据 sha 的要求,这是显示为图像的问题:
http://dl.dropbox.com/u/762638/Files/Images/Screenshots/show_combobox_extjs_problem/part_1.png
http://dl.dropbox.com/u/762638/Files/Images/Screenshots/show_combobox_extjs_problem/part_2.png
http://dl.dropbox.com/u/762638/Files/Images/Screenshots/show_combobox_extjs_problem/part_3.png
在这里您可以找到组合框代码:
Ext.define('Fdd.form.field.XComboBox', {
extend: 'Ext.form.field.ComboBox',
alias: 'widget.xcombobox',
displayField: 'display',
queryMode: 'local',
valueField: 'value',
//forceSelection: true,
/**
*
* @property {Ext.form.Panel} parentForm
* Contains a reference to the combobox form, used internally
*
* @readonly
*/
parentForm: null,
/**
*
* @property {Boolean} hasChanged
* `true` if the combobox has changed its value since last show/hide cycle
*/
hasChanged: false,
statics: {
xcomboboxRenderer: function(xcombobox) {
return function(value, metaData, record, rowIndex) {
if (value === null)
return '';
return xcombobox.store.getById(value.toString()).get('display');
}
}
},
initComponent: function() {
var me = this;
var xComboBoxStoreClass = 'Fdd.data.XComboBoxStore';
var xComboBoxStoreKey = Ext.getClassName(me);
// FIXME: Fix default value to be display and not value field
// Create the combo store if not exists
me.createComboStoreIfNotExists = function() {
// If store is not set, we can't do anything
if (!me.store)
return false;
// If the store is an array, we break the functionality and return to a normal combobox
// because XComboBox is to avoid problems with stores
if (Ext.isArray(me.store))
return false;
// We need the object for the parent store, to avoid missing references
var parentStore = null;
if (Ext.isString(me.store))
parentStore = Ext.getStore(me.store)
else
parentStore = me.store;
// If the store doesn't have the updatedAt variable, we don't enable functionalities
// because that is a requirement
if (!Ext.isDefined(parentStore.updatedAt))
return false;
// If parent store is of type XComboBoxStore, it means that we already have created a combo store
if (Ext.getClassName(parentStore) == xComboBoxStoreClass)
return false;
var comboStore = Fdd.NamespaceKeyedStoreManager.lookup(xComboBoxStoreKey, parentStore.storeId);
if (!comboStore) {
comboStore = Ext.create(xComboBoxStoreClass, parentStore);
Fdd.NamespaceKeyedStoreManager.register(xComboBoxStoreKey, parentStore.storeId, comboStore);
}
me.store = comboStore;
//me.on('afterrender', function(obj, eOpts) {
// obj.setValue(1);
//});
return comboStore;
}
// Load data if required
me.loadUpdatedData = function() {
me.createComboStoreIfNotExists();
if (me.store)
Fdd.NamespaceKeyedStoreManager.lookup(xComboBoxStoreKey, me.store.parentStore.storeId).loadIfNotUpdated();
};
// Load data if required
me.loadUpdatedData();
// Fires loadUpdatedData every time trigger is pressed
me.on('expand', function(obj) {
obj.loadUpdatedData();
});
// TODO: Building a fix for the problem combobox input field shows the value field instead of the display field
me.on('boxready', function(obj) {
obj.parentForm = obj.up('form');
console.log(obj.parentForm);
obj.mon(obj.parentForm, 'edit', function(editor) {
console.log("beforeaction");
console.log(e.originalValue);
console.log(obj);
if (!obj.hasChanged)
obj.setValue(obj.originalValue);
});
obj.mon(obj.parentForm, 'show', function() {
/*console.log("move:");
console.log(obj.getValue());
console.log(obj.inputEl.dom.value);*/
obj.hasChanged = false;
if (obj.parentForm) {
if (obj.getValue() === null)
obj.inputEl.dom.value = "";
else
obj.inputEl.dom.value = obj.store.getById(obj.getValue().toString()).get('display');
}
});
});
me.on('change', function(obj) {
obj.hasChanged = true;
});
// Call parent initializator
me.callParent(arguments);
}
});
我们所说的代码是从 TODO 开始的。
我建议忽略前面的部分,因为它用于创建存储副本以避免过滤和缓冲存储。
编辑2:
我试图通过这个问题解决的问题似乎与我试图解决的问题(以不同的方式解决)没有直接关系,因此可以关闭问题。
不管怎么说,还是要谢谢你。