當我整理的孩子,我已經得到了家長和孩子的價值,但它會就這樣產生(title1orangepinkyellowgreen,title1orangepinkyellowgreen,title1orangepinkyellowgreen,title1orangepinkyellowgreen),但我必須打印像這樣(Title1_orange,title_pink ...)jquery-sortable - 如何獲得父母和孩子的價值(Title1_orange,Title1_pink ...)?
var addPositions = function() {
$('.droptrue, .droptrue1').each(function() {
var position = 0;
$(this).children().each(function() {
$(this).data('position', position);
position++;
});
});
};
$(document).ready(function() {
var treeList = "";
treeList = "<ul id=\"createTree\" class=\"droptrue1 mt1\">";
for(var key in jsonObj){
//alert("key: " + key + ", value: " + jsonObj[key])
for (var skey in jsonObj[key]) {
treeList += ("<li class=\"listTree\" id=\"asdf\">"+skey +"<ul class=\"droptrue mt\">");
for (var sskey in jsonObj[key][skey]){
for (var ssskey in jsonObj[key][skey][sskey]){
treeList += ("<li class=\"innerList\">"+jsonObj[key][skey][sskey][ssskey]+"</li>");
}
}
treeList += "</ul></li>";
}
}
treeList += "</ul>";
$('#tree').append(treeList);
addPositions();
$(".droptrue").sortable({
connectWith: "ul.mt",
dropOnEmpty: true,
stop: function(event, ui) {
var order = [];
ui.item.closest('ul').children('li').each(function() {
order.push($(this).data('position'));
var c = $(this).text();
var z = $(this).parents().eq(1).text();
alert(z);
$("#cl").append(z+"<br />");
});
}
});
這裏撥弄鏈接:http://jsfiddle.net/thilakar/VKWeC/
感謝
我可以告訴你爲什麼這樣做。這是父母李項目。李項目雖然有它的列表。所以它將包括一切。你能在那裏創造一個跨度或者什麼,這樣你就可以達到那個跨度? – Matt