【发布时间】:2014-04-08 21:26:16
【问题描述】:
我有一个包含多个附加到远程商店的组合框字段的表单:
Ext.define('app.ux.form.MyCombo', {
extend: 'Ext.form.field.ComboBox',
alias: 'widget.mycombo',
store: this.store,
displayField: 'displayField',
valueField: 'valueField',
forceSelection: true,
autoSelect: true,
initComponent: function() {
this.addEvents('selectitem');
this.enableBubble('selectitem');
this.callParent(arguments);
this.listeners = {
change: function(field, value) {
this.fireEvent('selectitem', field, value);
}
}
}
})
fieldLabel: 'DisabilityType',
name: 'f_disability_type',
xtype: 'combo',
valueField: 'valueField',
displayField: 'displayField',
forceSelection: true,
autoSelect: true,
store: 'DisabilityTypes'
DisabilityTypes 是一个基本的 Ext.data.store,其中 autoLoad 设置为 false,autoSync 设置为 true。当您单击与商店关联的下拉菜单时,商店会加载并显示值列表。
当我在包含此下拉列表的 BasicForm 对象上调用 loadRecord 并向其传递模型时,它会填充使用本地存储的组合框,但不会加载使用远程存储的组合框。这是因为组合框存储未加载 (autoLoad: false) 或组合框在表单加载后加载 (autoLoad:true)。
我知道这是 Ext 3.3.x 中的一个问题,并且有一个插件可以解决它:
/**
* When combo box is used on a form with dynamic store (remote mode)
* then sometimes the combobox store would load after the form data.
* And in that case the setValue method of combobox will not
* set the combobox value properly. This override makes sure that the
* combobox store is completely loaded before calling the setValue method.
*/
Ext.override(Ext.form.ComboBox, {
setValue : function(v){
var text = v;
if(this.valueField){
if(!Ext.isDefined(this.store.totalLength)){
this.store.on('load', this.setValue.createDelegate(this, arguments), null, {single: true});
if(this.store.lastOptions === null){
var params;
if(this.valueParam){
params = {};
params[this.valueParam] = v;
}else{
var q = this.allQuery;
this.lastQuery = q;
this.store.setBaseParam(this.queryParam, q);
params = this.getParams(q);
}
this.store.load({params: params});
}
return;
}
var r = this.findRecord(this.valueField, v);
if(r){
text = r.data[this.displayField];
}else if(this.valueNotFoundText !== undefined){
text = this.valueNotFoundText;
}
}
this.lastSelectionText = text;
if(this.hiddenField){
this.hiddenField.value = v;
}
Ext.form.ComboBox.superclass.setValue.call(this, text);
this.value = v;
}
});
这个问题在 Ext 4 中得到解决了吗?还是我需要找到另一个兼容 Ext 4 的插件?
【问题讨论】:
-
它工作正常,至少在 4.0.7 中,我不知道您使用的是哪个版本,但如果我在尚未加载商店且商店有 autoLoad 的组合上调用 setvalue() :true,然后它首先加载存储,然后设置值。
标签: extjs4