Ⅰ 如何把後台數據轉換成json格式,
嘎嘎 newtonsoft.json 去搜索這個dll 或者自己手寫一個 用字元串拼一下 jsonConvert轉換也行
Ⅱ 要用jQuery的nestable()做一個三級樹形菜單,值全部從資料庫動態獲取
$.ajax({ url:"url",
type:"GET",
async:false,
dataType:'json',
success:function(dataJSON){
fn(dataJSON.data, $("#htmll"));
},
error:function(msg){error(msg);}
})
function fn(array, html) {
for (var i = 0; i < array.length; i++) {
var object = array[i];
var data = "";
var temp = '';
if (object.subs) {
var e = $("<ol class='dd-list'></ol>");
var f = $("<li class='dd-item' data-id='"+object.id+"'> <div class='dd-handle' id='"+object.id+"' ondblClick='aa(this)'>"+ object.name + "</div></li>");
f.append(e);
html.append(f);
fn(object.subs,e);
} else {
html.append("<li id='"+object.id+"' data-id='"+object.id+"' class='dd-item' ondblClick='aa(this)'><div class='dd-handle'>" +object.name + "</div></li>");
}
}
}