(转)extJs combox 动态下拉框联动(级联)

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 17:26   1361   0
首先,两个下拉框,第一个下拉框首先load数据源,在select的事件中在load第二个数据源,这就是一个简单的二级联动的实现原理了.
Js代码  
//  第一个下拉框  
var parentStore = new Ext.data.Store({  
    proxy: new Ext.data.HttpProxy({  
        url: 'loadByParentid.action?parentid=1001'  
    }),  
    reader: new Ext.data.JsonReader({  
    root: 'list',  
    id: 'id'  
    }, [  
        {name: 'id', mapping: 'id'},  
        {name: 'mc', mapping: 'name'}  
    ])  
});   
//     第二个下拉框  
var childStore = new Ext.data.Store({  
    proxy: new Ext.data.HttpProxy({  
        url: '#'  
    }),  
    reader: new Ext.data.JsonReader({  
    root: 'list',  
    id: 'id'  
    }, [  
        {name: 'id', mapping: 'id'},  
        {name: 'mc', mapping: 'name'}  
    ])  
});
parentStore.load();

Ext.form.ComboBox({      fieldLabel:
'请选择分类', xtype:'combo', store: parentStore, valueField :"id", displayField: "mc", mode: 'local', forceSelection: true,//必须选择一项 emptyText:'请选择分类...',//默认值 hiddenName:'interviewsDetail.parent_category',//hiddenName才是提交到后台的input的name editable: false,//不允许输入 triggerAction: 'all',      id :'parent_id', name: 'parent',    width: 400,   listeners:{ select : function(combo, record,index){ childStore.proxy= new Ext.data.HttpProxy({url: 'loadByParentid.action?parentid=' + combo.value}); childStore.load(); } } });

    Ext.form.ComboBox({ xtype:
'combo', store: childStore, valueField :"id", displayField: "mc", //数据是在本地 mode: 'local', forceSelection: true,//必须选择一项 emptyText:'请选择子分类...',//默认值 hiddenName:'interviewsDetail.child_category',//hiddenName才是提交到后台的input的name editable: false,//不允许输入 triggerAction: 'all', fieldLabel: '选择', id : 'child_id', name: 'child',      width: 400 });

转载于:https://www.cnblogs.com/hb-strive/archive/2013/04/10/3012406.html

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP