Ext的Combox说法不一,自己实现了一下,有好的方法请给胖子留言。
文件目录
|--resource_type_combx.js
|--resource_type_combx.json
resource_type_combx.js文件
Ext.onReady(function(){
//读JSON
var resourceTypeStore= new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: "resource_type_combx.json"
}),
reader: new Ext.data.JsonReader({
fields: [
"resource_type_title","selected","resource_type_id"
]
})
});
resourceTypeStore.load();
//设置默认值
resourceTypeStore.on("load",function(ds,records,o){
for(i=0;i<records.length;i++){
if(records[i].data.selected=="yes"){
combo.setValue(records[i].data.resource_type_title);
}
}
});
var combo = new Ext.form.ComboBox({
name:"combox",
fieldLabel: "资源类型",
hiddenName:"实际后台取值的name名",
store: resourceTypeStore,
displayField:"resource_type_id",
valueField:"resource_type_title",
typeAhead: true,
mode: "local",
triggerAction: "all",
emptyText:"Select a state...",
selectOnFocus:true,
applyTo: "local-states",
valueNotFoundText:1,
editable:false,
//得到选中的返回值
listeners:{
select: function(combo, record, index) {
alert(combo.getValue());
}
}
});
});
resource_type_combx.json文件
[
{"resource_type_title":"Extjs","resource_type_title":"1"},
{"resource_type_title":"Extjs1","resource_type_title":"2"},
{"resource_type_title":"extjs3","resource_type_title":"3","selected":"yes"}
]
本文介绍了一种使用ExtJS框架创建ComboBox组件的方法。通过加载JSON数据来填充ComboBox,并设置了默认选中项。此外,还实现了ComboBox的选择监听事件。
1377

被折叠的 条评论
为什么被折叠?



