Ⅰ 如何把后台数据转换成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>");
}
}
}