后台方法:
1
JSONArray json
=
new
JSONArray();
2 String pareId = request.getParameter( " dicId " );
3 List list = zhidaoBO.getQuestionTDicByParentId(pareId); // 返回一个list
4 json = JSONArray.fromObject(list);
5 return super .ajaxReturnJSON(request, response, json.toString());
2 String pareId = request.getParameter( " dicId " );
3 List list = zhidaoBO.getQuestionTDicByParentId(pareId); // 返回一个list
4 json = JSONArray.fromObject(list);
5 return super .ajaxReturnJSON(request, response, json.toString());
然后在回调函数里用js去操作
1
$.post(
"
<c:url value='/user/zhidao/do.ao?method=getChildClass'/>
"
,
2 { " dicId " :id},
3 function(json){
4 json = eval( ' ( ' + json + ' ) ' );
5 var obj = $( " #childSelect " );
6 obj.empty();
7 for (var i = 0 ;i < json.length;i ++ ){
8 // obj.append(<option value='" + json[i][0] + "'
οnclick='optionSelect(""" + json[i][0] + """)'>" + json[i][1] + "</option>");
9 obj.append( " <option value=' " + json[i][ 0 ] + " '> " + json[i][ 1 ] + " </option> " );
10 }
11 });
2 { " dicId " :id},
3 function(json){
4 json = eval( ' ( ' + json + ' ) ' );
5 var obj = $( " #childSelect " );
6 obj.empty();
7 for (var i = 0 ;i < json.length;i ++ ){
8 // obj.append(<option value='" + json[i][0] + "'
οnclick='optionSelect(""" + json[i][0] + """)'>" + json[i][1] + "</option>");
9 obj.append( " <option value=' " + json[i][ 0 ] + " '> " + json[i][ 1 ] + " </option> " );
10 }
11 });
或者
$.each(data,function(i){
$("<option value='"+data[i][0]+"'>"+data[i][1]+"</option>").appendTo("#list1");
});