日期:2014-05-16  浏览次数:20379 次

ExtJS中关于ComboBox加载后台数据

今天忙了一天,终于解决了让我头疼的ComboBox加载后台数据,作为一个菜鸟新手,自己独立解决了一个困扰已久的问题,真是十分欣慰啊,呵呵,来不及就想拿出来和大家分享一下!

Ext.onReady(function(){
	var storeProvince = new Ext.data.JsonStore({
        autoLoad:true,
        url : "http://localhost:8080/HyitSystem/testCombo.action",
        root : "provincelist",
        fields : [{
        	name : 'id'
        }, {
            name : 'province'
        }]
    });
     var comboProvince = new Ext.form.ComboBox({
        store: storeProvince,
        name:'cName',
        fieldLabel:"选择省",
        mode: 'local',
        triggerAction: 'all',
        valueField: 'id',
        displayField: 'province',
        hiddenName:'id',
        emptyText: '请选择所在省',
        blankText: '请选择...',
        selectOnFocus: true,
        allowBlank: false,
        editable: false
    });
	var form = new Ext.form.FormPanel({
		labelAlign : 'right',
		labelWidth : 60,
		renderTo:Ext.getBody(),
		title:"级联选择",
		width:290,
		frame : true,
    	items : [{
              layout : 'form',
              items : [comboProvince]
        }]
	})
})

?后台数据输出样式如下:

{"provincelist":[{"id":1,"province":"河南省"},{"id":2,"province":"河北省"},{"id":3,"province":"山西省"},{"id":4,"province":"山东省"},{"id":5,"province":"湖南省"},{"id":6,"province":"湖北省"},{"id":7,"province":"四川省"},{"id":8,"province":"辽宁省"},{"id":9,"province":"吉林省"},{"id":10,"province":"黑龙江省"},{"id":11,"province":"广东省"},{"id":12,"province":"浙江省"},{"id":13,"province":"福建省"},{"id":14,"province":"甘肃省"},{"id":15,"province":"江西省"},{"id":16,"province":"陕西省"},{"id":17,"province":"海南省"},{"id":18,"province":"江苏省"},{"id":19,"province":"安徽省"},{"id":20,"province":"云南省"},{"id":21,"province":"贵州省"},{"id":22,"province":"天津市"},{"id":23,"province":"北京市"},{"id":24,"province":"上海市"},{"id":25,"province":"重庆市"},{"id":26,"province":"新疆维吾尔族自治区"},{"id":27,"province":"内蒙古自治区"},{"id":28,"province":"西藏自治区"},{"id":29,"province":"广西壮族自治区"},{"id":30,"province":"宁夏回族自治区"},{"id":31,"province":"香港特别行政区"},{"id":32,"province":"澳门特别行政区"}]}

?一定要保证输出格式的正确哦,不然就加载不了了。