combox 默认值

[
    {"abbr":"AL","state":"Alabama"},
    {"abbr":"WY","state":"Wyoming"},
    {"abbr":"YY","state":"YYTest"}
]






	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); 
		 
	}); 


----------------------------------------------------------------------------


[
    {"abbr":"AL","state":"Alabama"},
    {"abbr":"WY","state":"Wyoming"},
    {"abbr":"YY","state":"YYTest","selected":"y"}
]

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());   
              }
          }
    });
});

你可能感兴趣的:(json,ext)