實現效果如下:
顯示頁面的JQ代碼事例:
$.ajax({
url: "${ctx}/resource/getResName" , //後臺方法名稱
type: "post",
dataType: "json",
traditional: true,
success: function (data) {
var res =data.resls;
var optionstring = "";
for (var j = 0; j < res.length; j++) {
optionstring += "" + res[j].res_name + "";
}
$("#ques_name").html("請選擇... "+optionstring);
},
error: function (msg) {
alert("下拉框加載出錯了!");
}
}); import cn.sjz.sfj.model.LearnResource;
import java.util.List;
public void getResName(){
String sql = "select res_id, res_name from learn_resource";
List resls = LearnResource.dao.find(sql);
setAttr("resls",resls);
renderJson();
}
顯示頁面的select標籤代碼事例:
Controller裏的方法:
$.ajax({
url: "${ctx}/resource/getResName" , //後臺方法名稱
type: "post",
dataType: "json",
traditional: true,
success: function (data) {
var res =data.resls;
var optionstring = "";
for (var j = 0; j < res.length; j++) {
optionstring += "" + res[j].res_name + "";
}
$("#ques_name").html("請選擇... "+optionstring);
},
error: function (msg) {
alert("下拉框加載出錯了!");
}
}); import cn.sjz.sfj.model.LearnResource;
import java.util.List;
public void getResName(){
String sql = "select res_id, res_name from learn_resource";
List resls = LearnResource.dao.find(sql);
setAttr("resls",resls);
renderJson();
}