我想用以下数组创建一个组合框:
var operators = new Array(">=",">","=~","","!=","=","<","<=");
问题是我希望第一个元素(有时是最后一个元素)成为comboxbox的默认值。我找不到如何成功地做到这一点。
非常感谢,如果重复,请表示歉意。
修改
var ops = new Array(">=",">","=~","","!=","=","<","<=");
var operators = new Ext.data.ArrayStore({ id: 0, fields: [ 'value' ], data: ops });
Ext.getCmp('variablesAttributesPanel').add({xtype: 'combo', id: variables[j].getTitle() + 'MinCombo', mode: 'local', valueField: 'value', displayField: 'value', store: operators, width: 50, x: 240, y: (j * 20 + 19), editable: false, allowBlank: false});
这是在下拉列表中添加选项&gt;,= ,,!,&lt;
有什么想法吗?
答案 0 :(得分:3)
确保在组合框配置
中设置triggerAction triggerAction : 'all'
var operators = new Array(">=",">","=~","x","!=","=","<","<=");
var test1 = new Ext.form.ComboBox({
height:100,
width:100,
store: operators
});
var test2 = new Ext.form.ComboBox({
height:100,
width:100,
triggerAction: 'all',
store: operators
});
var win=new Ext.Window({
renderTo:Ext.getBody(),
items:[test1,test2],
height:300,
width:300,
title:'comboWin'
}).show();
test1.setValue(operators[1]);
test2.setValue(operators[2]);
答案 1 :(得分:0)
使用组合框的setValue方法。在这种情况下,显示和值是相同的,因此您只需传入数组值:
comboBox.setValue(operators[0]);