`
qinya06
  • 浏览: 583093 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

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());   
              }
          }
    });
});
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics