- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 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');
}
}
关于combobox - 如何从 extjs Controller 设置组合框的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17611831/
我是一名优秀的程序员,十分优秀!