gpt4 book ai didi

combobox - 如何从 extjs Controller 设置组合框的值

转载 作者:行者123 更新时间:2023-12-02 19:16:59 24 4
gpt4 key购买 nike

我在 extjs4 中工作。我有一个组合框,代码为-

{
margin:'7 6 5 5',
xtype:'combobox',
fieldLabel:'Language',
name:'language',
id:'combo',
width:190,
allowBlank:false,
emptyText: '--Select language--',
labelWidth: 60,
store: new Ext.data.ArrayStore({
fields: ['id','value'],
data: [
['1','Marathi'],
['2','English']
]
}),
queryMode: 'local',
valueField:'id',
displayField:'value',
editable:false
},

在我的整个功能中,我想将组合框的值默认设置为用户的选择。那么如何从 Controller 设置组合框的值

最佳答案

要选择默认值,您可以使用事件监听器。渲染组合框后,您可以使用 setValue() 设置所需的值方法来自 Ext.form.field.Field如果您需要按需选择组合框值,您可以使用 Ext.getCmp('combo') 获取它然后使用 setValue()甚至更好设置 itemId而不是 id 并使用 componentQuery获取组合框并设置值:

Ext.ComponentQuery.query('#combo')[0].setValue('2');

setValue( value ) : Ext.form.field.Field Sets the specified value(s) into the field. For each value, if a record is found in the store that matches based on the valueField, then that record's displayField will be displayed in the field. If no match is found, and the valueNotFoundText config option is defined, then that will be displayed as the default field text. Otherwise a blank value will be shown, although the value will still be set.

listeners:{
scope: this,
afterRender: function(me){
me.setValue('1');
}
}

这是一个 example在 fiddle 中

关于combobox - 如何从 extjs Controller 设置组合框的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17611831/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com