$(function(){
$("#btn_getData")
.click(function(){
$.post("getParentDict.action",function(data){
var obj=$(eval(data));
var sel=$("#sel_mianNodes");
sel.find("option").remove();
obj.each(function(i,item){
var content="<option value='"+item.dicid+"'>"+item.dicname+"</option>";
sel.append(content);
});
});
});
$("#sel_mianNodes")
.change(function(){
$.post("queryJasonDict.action",{parentId:$(this).val()},function(data){
var obj=$(eval(data));
var sel=$("#sel_child");
sel.find("option").remove();
obj.each(function(i,item){
var content="<option value='"+item.dicid+"'>"+item.dicname+"</option>";
sel.append(content);
});
});
});
});
public void getParent(){
List<Dictinfo> list_dic=dicDao.getParent();
StringBuffer strBuf=new StringBuffer("{[");
for(Dictinfo dic : list_dic){
strBuf.append("{dicid:'"+dic.getDicid()+"',dicname:'"+dic.getDicname()+"',dicvalue:'"+dic.getDicvalue()+"'},");
}
strBuf.deleteCharAt(strBuf.lastIndexOf(","));
strBuf.append("]}");
try {
ServletActionContext.getResponse().setCharacterEncoding("UTF-8");
PrintWriter pwriter=ServletActionContext.getResponse().getWriter();
pwriter.write(strBuf+"");
pwriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public void queryJson(String parentId){
System.err.println("in~");
List<Dictinfo> list_dic=dicDao.getChild(parentId);
StringBuffer strBuf=new StringBuffer("{[");
for(Dictinfo dic : list_dic){
strBuf.append("{dicid:'"+dic.getDicid()+"',dicname:'"+dic.getDicname()+"',dicvalue:'"+dic.getDicvalue()+"'},");
}
strBuf.deleteCharAt(strBuf.lastIndexOf(","));
strBuf.append("]}");
System.out.println(strBuf);
try {
ServletActionContext.getResponse().setCharacterEncoding("UTF-8");
PrintWriter pwriter=ServletActionContext.getResponse().getWriter();
pwriter.write(strBuf+"");
pwriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}