gpt4 book ai didi

javascript - ExtJS组合设置问题

转载 作者:行者123 更新时间:2023-11-28 16:38:25 24 4
gpt4 key购买 nike

我在输入表单中使用组合时遇到了一个有趣的问题。我的表单包含从 json 存储获取数据的组合。添加新记录时它工作正常,但当打开表单编辑现有记录时,有时 id 显示为已选择而不是其值(例如:有 5 而不是“apple”)。我认为它会尝试在完成加载组合之前设置该值。

有办法解决这个问题吗?我把创建组合的代码放在这里:

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

胡比杜比

最佳答案

bmoaskau 你的解决方案很好,我更喜欢通过我的组合插件来做到这一点。尝试一下,对我来说就像一个魅力,将它绑定(bind)到组合只需添加

plugins: new Application.plugins.comboloadvalue(),

到你的组合配置对象

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;
}

});

关于javascript - ExtJS组合设置问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2506312/

24 4 0
文章推荐: compiler-errors - 如何设置 JScript(不是 JScript.NET)开发环境?
文章推荐: html - 是否可以在 Safari 中独立于