$(function(){
var data=[{ ... }]; //json树形字符串
$("#dataInput").click(function(){
var options="";
var count=8;
if(data.length==1){
options = displayMenu(data[0], options,count);
}
$("#ss").html(options);
});
});
function displayMenu(model, options,count) {
count=count+8;
for(var j=0;j<model.children.length;j++){
var childs = model.children;
options = options + "<li>"+getEmptyString(count)+childs[j].displayName+"</li>";
if (childs.length > 0) {
options = displayMenu(childs[j], options,count);
}
}
return options;
};
function getEmptyString(count){
var text = '';
for(var i=0;i<count;i++){
text=text+' ';
}
return text;
}