日期:2014-05-17 浏览次数:20767 次
private String getListJSON(List list) {
if (list == null) {
return "";
}
StringBuffer sb = new StringBuffer();
sb.append("[");
DictModel dm = null;
for (int i = 0; i < list.size(); i++) {
dm = (DictModel) list.get(i);
sb.append(getJSONdata(dm));
if (i != list.size() - 1) {
sb.append(",");
}
}
sb.append("]");
return sb.toString();
}
private String getJSONdata(DictModel dm) {
if (dm == null) {
return "";
}
StringBuffer sb = new StringBuffer();
sb.append("{");
sb.append("id:" + dm.getId() + ",");
sb.append("pid:" + dm.getPid() + ",");
sb.append("name:\"" + dm.getName() + "\",");
sb.append("ord:" + dm.getOrd());
sb.append("}");
return sb.toString();
}
$(document).ready(function(){
$.ajax({
url: "<%=path%>/modelAction.do",
data: {
pid:"-1",
method:"query"
},
type: "GET",
cache: false,
async: false,
success: function(data){
var dataObj=eval("("+data+")");
dataObj.sort(function(a,b){
return a["ord"]>b["ord"]?1:a["ord"]==b["ord"]?0:-1
});
$.each(dataObj,function(i,d){
$("<option value='"+d['id']+"'>" +d['name']+"</option>").appendTo("#bq");
});