Ext JS百强应用:ComboBox是什么?怎么使用?--第2强
Ext JS 的ComboBox是什么? 说白了,就是下拉列表+文本,只不过更丰富!
怎么使用?
Ext.onReady(function () {
var store = Ext.create("Ext.data.Store", {
fields: ["abbr", "name"],
data: [
{ "abbr": "wbg", "name": "wubangguo" },
{ "abbr": "wjb", "name": "wenjiabao" },
{ "abbr": "hjt", "name": "hujintao" },
{ "abbr": "lks", "name": "likeshan"}],
sorters: ["abbr"] //排序
});
Ext.create("Ext.form.ComboBox", {
fieldLabel: "Choose Name",
store: store, //加载数据源
queryMode: "local", //如果数据是在本地的话,最好使用这个选项,这样就会有助于提高性能,默认情况是remote(注意在我们通过ajax请求返回数据到本地的store时也要使用local选项,因为如果不这样的话,就会多请求服务器一次)
displayField: "name",
valueField: "abbr",
forceSelection: true, //只允许从下拉列表中进行选择,不能输入文本
editable: false, //不允许编辑,(默认为true)
multiSelect: true, //那么这种情况就是允许选择多个项,而且多个项也会显示在combobox中(默认情况是false)
listeners: {
scope: this,
"select": function (comboBox, record, index) {
Ext.Array.each(record, function (item) {
alert(item.get("name"));
});
alert(comboBox.getValue()); //这个是获取value的不是获取到显示在哪里的值
}
},
renderTo: Ext.getBody()
});
});


浙公网安备 33010602011771号