我的Sqlite数据库数据: -
ID ParentId Item
1 0 Food
2 1 Indian
3 2 Full Meal
4 2 Meal
5 4 Roti
6 4 Dal
7 0 Chinese
8 7 Soup
9 8 Momo
10 9 Noodle
在Jquery: -
for ( var i = 0; i < results.rows.length; i++) {
var food_Id = results.rows.item(i).ID ;
var food_PId = results.rows.item(i).ParentId;
var food_Item = results.rows.item(i).Item;
if(food_PId == 0){
sfoodID = food_Id;
foodscripts += '<li><a href="#" class="d-main-menu">'
+'<img src="images/1.png" class="e-left" />'
+'<span class="d-menu-parent-text e-left">'+food_Item+'</span></a>'
}else{
foodscripts += '<ul>'
for(var j = 0; j < results.rows.length; j++ ){
var food_Id_s = results.rows.item(j).ID ;
var food_PId_s = results.rows.item(j).ParentId ;
var food_Item_s = results.rows.item(j).Item;
if(sfoodID == food_PId_s){
foodscripts += '<li><a href="">'+food_Item_s+'</a></li>'
}
}
foodscripts += '</ul>'
}
foodscripts += '</li>'
}
请帮助我,如果我现在没有多少级别
我已经完成了一个级别并且
如何处理该级别内的两个或三个子级别
答案 0 :(得分:1)
您好我设置了 Demo
,其中添加了嵌套ul
与您提供的数据。
您需要进行一些更改我从虚拟源获取数据,如此
var dataArray = new Array();
var data = new Array();data['ID'] = 1;data['ParentId'] = 0;data['Item'] = 'Food';dataArray.push(data);
var data = new Array();data['ID'] = 2;data['ParentId'] = 1;data['Item'] = 'Indian';dataArray.push(data);
var data = new Array();data['ID'] = 3;data['ParentId'] = 2;data['Item'] ='Full Meal';dataArray.push(data);
var data = new Array();data['ID'] = 4;data['ParentId'] = 2;data['Item'] = 'Meal';dataArray.push(data);
var data = new Array();data['ID'] = 5;data['ParentId'] = 4;data['Item'] = 'Roti';dataArray.push(data);
var data = new Array();data['ID'] = 6;data['ParentId'] = 4;data['Item'] ='Dal';dataArray.push(data);
var data = new Array();data['ID'] = 7;data['ParentId'] = 0;data['Item'] = 'Chinese';dataArray.push(data);
var data = new Array();data['ID'] = 8;data['ParentId'] = 7;data['Item'] = 'Soup';dataArray.push(data);
var data = new Array();data['ID'] = 9;data['ParentId'] = 8;data['Item'] ='Momo';dataArray.push(data);
var data = new Array();data['ID'] = 10;data['ParentId'] = 9;data['Item'] = 'Noodle';dataArray.push(data);
var food_Id = dataArray[i].ID;
var food_PId = dataArray[i].ParentId;
var food_Item = dataArray[i].Item;
而不是这个
var food_Id = results.rows.item(i).ID ;
var food_PId = results.rows.item(i).ParentId;
var food_Item = results.rows.item(i).Item;