首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

Ext中省市级联奇效

2012-10-24 
Ext中省市级联特效//定义班级数据加载器var gradeStorenew Ext.data.Store({ proxy:new Ext.data.HttpPro

Ext中省市级联特效
//定义班级数据加载器
var gradeStore=new Ext.data.Store({
proxy:new Ext.data.HttpProxy({
  url:'grade.do?method=showGradeName'
  }),
  reader:new Ext.data.JsonReader({
   root:'gradenamejs'
  },[
  {name:'gradeid'},
  {name:'gradename'}
  ])
});
//定义老师的store
var teacherStore=new Ext.data.Store({
  proxy:new Ext.data.HttpProxy({
   url:'grade.do?method=showTeacher&command=getTeaher'//这个地址可以随便给
  }),
  reader:new Ext.data.JsonReader({
   root:'teacherjs'
  },
  [{name:'gradeid'},
  {name:'teacher'}
  ])
});

var gradeField=new Ext.form.ComboBox({
fieldLabel:'班级名称',
name:'gradename',
allowBlank:false,
mode:'local',
hiddenName:'gradename',//提交到后台中select中的值
editable:false,
triggerAction:'all',
emptyText:'请选择班级',
store:gradeStore,
listeners:{
   select:function(combox,record,index){
    teacherFeild.clearValue();//实现下拉框的值的变更
    teacherStore.proxy=new Ext.data.HttpProxy({
       url:'grade.do?method=showTeacher&gradeid='+combox.value 
    });//动态显示老师姓名
    teacherStore.load();
   }
},
valueField:'gradeid',
displayField:'gradename'
});

//加载班级的下拉框的值
gradeStore.load();

//老师的下拉框
var teacherFeild=new Ext.form.ComboBox({
  xtype:'combox',
  store:teacherStore,
  valueField:'gradeid',
  displayField:'teacher',
  model:'local',
  emptyText:'请选择老师',
  hiddenName:'teacher',
  editable:false,
  triggerAction:'all',
  fieldLabel:'班主任',
  name:'teacher'
});

//然后将这两个下拉框渲染到form中
//在action中产生js
try {
response.setCharacterEncoding("gbk");
PrintWriter out=response.getWriter();
//构建array数组
List<Grade> list=this.iservice.showAll("from Grade");
String json="{gradenamejs:[";
for (int i = 0; i < list.size(); i++) {
Grade grade=(Grade)list.get(i);
json+="{gradeid:"+grade.getGradeid()+",gradename:'"+grade.getGradename()+"'},";
}
json=json.substring(0,json.length()-1);
json+="]}";
out.write(json);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
return null;

热点排行