当前位置:   article > 正文

[ javascript ] Json中添加List!

[ javascript ] Json中添加List!
后台java代码!
  1. obj = questionService.showSubjectInfo(subjectid,subjectType);
  2. Teacher teacher = (Teacher) ActionContext.getContext().getSession()
  3. .get("teacherInfo");
  4. int departid = teacher.getDepartment().getDepartId();
  5. List<Object[]> courseList = courseService.findAllCourseByDepart(1, 10, departid);
  6. Object[] o = new Object[]{courseList};
  7. obj.add(o);
  8. return "success";


javascript代码:

  1. var data = xmlReq.responseText;
  2. var list = eval("(" + data + ")");
  3. var div = document.getElementById("dialog");
  4. var result = "请选择课程:<select>";
  5. var courses = list.obj[1];
  6. var courseList = courses[0];
  7. for(var k = 0 ; k< courseList.length ; k ++){
  8. var courseVal = courseList[k];
  9. result +="<option value = '" + courseVal[0]+ "' > " +courseVal[1]+"</option>";
  10. }
  11. result += "</select><br/>";
  12. for(var i = 0 ; i < list.obj.length; i ++){
  13. var o = list.obj[i];
  14. if(i ==0){
  15. result += "<lable>title</lable><br/><span><textarea name = 'title' style = 'width:90%;height:100px;'>" + o[1]+ "</textarea></span><br/><label>options</label><br/>";
  16. result += "<table border = '1' id = 'mytable'>";
  17. var arr = new Array();
  18. arr = o[2].split('‖');
  19. for(var j = 0 ; j < arr.length; j=j +2){
  20. result += "<tr><td><span><input type = 'checkbox'/></td><td>  " + arr[j]+ "<input class = 'answer' name = 'selectOption' type = 'text' value = '" + arr[j + 1]+"'/></span></td></tr>";
  21. }
  22. }
  23. }
  24. result += "</table><input type = 'submit' value = '增加选项' onclick = 'addOption()'><input type = 'submit' value = '删除选项' onclick = 'delOption()'/><br/></input><input type = 'submit' value = 'update' onclick = 'updateSelect()'>"
  25. div.innerHTML = result;
  26. show();


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/618601
推荐阅读
相关标签
  

闽ICP备14008679号