Javascript 加载组合框 extjs 的默认值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3489189/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Load default value for a comboBox extjs
提问by cranberies
how can i load a default value from my json store (remote) into a combobox , i've tried load the store before render the combo , and use setValue() i want my combo to display the first result in the store plz tell me the right way to do this and thanx
我如何将默认值从我的 json 存储(远程)加载到组合框,我已经尝试在呈现组合之前加载存储,并使用 setValue() 我希望我的组合在存储中显示第一个结果请告诉我这样做的正确方法和thanx
回答by Mchl
You need to set the valueproperty to the value of the first element after the store is loaded
您需要将value属性设置为商店加载后的第一个元素的值
Ext.ns('MyNamespace');
MyNamespace.MyComboBox = Ext.extend(Ext.form.ComboBox, {
displayField: 'displayValue',
triggerAction: 'all',
valueField: 'ID',
initComponent: function () {
this.store = new Ext.data.JsonStore({
url: 'url',
baseParams: {
//params
},
fields: [
{name:'ID', mapping: 'ID', type: 'int'},
{name:'displayValue', mapping: 'displayValue', type: 'string'},
],
root: 'root'
});
var me = this;
this.store.on('load',function(store) {
me.setValue(store.getAt(0).get('ID'));
})
MyNamespace.MyComboBox.superclass.initComponent.call(this);
this.store.load();
}
});

