[color=red][
{"abbr":"AL","state":"Alabama"},
{"abbr":"WY","state":"Wyoming"},
{"abbr":"YY","state":"YYTest"}
][/color]
----------------------------------------------------------------------------
[color=red][
{"abbr":"AL","state":"Alabama"},
{"abbr":"WY","state":"Wyoming"},
{"abbr":"YY","state":"YYTest","selected":"y"}
][/color]
{"abbr":"AL","state":"Alabama"},
{"abbr":"WY","state":"Wyoming"},
{"abbr":"YY","state":"YYTest"}
][/color]
var assPost=new Ext.data.JsonStore({
url:'../juniorTaskDetail/postList.action',
root: 'data',
fields : ['abbr','state']
});
assPost.on('load', function() {
var firstValue = assPost.getRange()[0].data.value;
assPost.setValue(firstValue);
});
----------------------------------------------------------------------------
[color=red][
{"abbr":"AL","state":"Alabama"},
{"abbr":"WY","state":"Wyoming"},
{"abbr":"YY","state":"YYTest","selected":"y"}
][/color]
Ext.onReady(function(){
//读JSON
var store = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: "combox.json"
}),
reader: new Ext.data.JsonReader({
fields: [
"abbr","state","selected"
]
})
});
store.load();
//设置默认值
store.on("load",function(ds,records,o){
for(i=0;i<records.length;i++){
if(records[i].data.selected=="y"){
combo.setValue(records[i].data.abbr);
}
}
});
var combo = new Ext.form.ComboBox({
name:"combox",
fieldLabel: "地区",
hiddenName:"area",
store: store,
displayField:"state",
valueField:"abbr",
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());
alert(combo.getValue+'-'+combo.getRawValue());
}
}
});
});