ExtJS的组合设置问题 [英] ExtJS combo setting problem
问题描述
我碰到一个有趣的问题,而在输入表单中使用连续技。我的表单包含得到JSON数据存储组合。 添加新记录时,它工作正常,但是当打开表单编辑现有的记录,有时选择的不是它的id值出现(如:有5而不是苹果)。我认为它会尝试之前完成加载组合来设置的值。
I run into an interesting problem while was using combos in input form. My form contains combos that get data from json stores. It works fine when adding new record, but when the form is opened for editing an existing record, sometimes the id appears as selected not its value (eg: there's 5 instead of "apple"). I think it tries to set the value before it finishes loading the combo.
有没有办法解决呢? 我把code到这里,创造连击:
Is there a way to solve this? I put the code down here that creates combos:
function dictComboMaker( store, fieldLabel, hiddenName, name, allowBlank, myToolTipp ) {
comboo = {
xtype : 'combo',
id: 'id-'+name,
allowBlank: allowBlank,
fieldLabel : fieldLabel,
forceSelection : true,
displayField : 'value',
valueField : 'id',
editable: false,
name: name,
hiddenName : hiddenName,
minChars : 2,
mode: 'remote',
triggerAction : 'all',
store : store
};
function dictJsonMaker(url) {
store = new Ext.data.JsonStore({
root : 'results', // 1
fields : [ 'id','value' ],
url : url,
autoLoad: true});
return store;
}
var comboKarStore = dictJsonMaker('/service/karok');
var comboKar= dictComboMaker(comboKarStore, 'Kar', 'karid', 'kar', false, '');
// then comboKar is added to the form
Hubidubi
Hubidubi
推荐答案
bmoaskau您的解决方案是好的我preFER通过插件为我的组合来做到这一点。试试看,用得好好的对我来说,将其绑定到一个组合只需添加
bmoaskau your solution is good i prefer to do this via a plugin for my combos. give it a try, works like a charm to me, to bind it to a combo simply to add
plugins: new Application.plugins.comboloadvalue(),
到您的组合配置对象
to your combo config object
Ext.ns('Application.plugins');
Application.plugins.comboloadvalue = Ext.extend(Ext.util.Observable, {
field : null,
init : function(field){
var self = this;
this.field = field;
this.store = field.getStore();
this.setLoaded(false);
this.store.on('load', function(){
return self.onLoad();
}, this);
},
onLoad : function(){
if(this.store !== null){
this.field.setValue(this.field.getValue());
this.setLoaded(true);
}
return true;
},
setLoaded: function(bool){
this.store.hasOnceLoaded = bool;
},
getLoaded: function(){
return this.store.hasOnceLoaded;
}
});
这篇关于ExtJS的组合设置问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!