").addClass("node")
.data("tree-node", nodeCount)
.append($nodeContent);
// Expand and contract nodes
if ($childNodes.length > 0) {
// $nodeDiv.click(function () {
// var $this = $(this);
// var $tr = $this.closest("tr");
//
// if ($tr.hasClass('contracted')) {
// $this.css('cursor', 'n-resize');
// $tr.removeClass('contracted').addClass('expanded');
// $tr.nextAll("tr").css('visibility', '');
//
// // Update the
appropriately so that if the tree redraws collapsed/non-collapsed nodes
// // maintain their appearance
// $node.removeClass('collapsed');
// } else {
// $this.css('cursor', 's-resize');
// $tr.removeClass('expanded').addClass('contracted');
// $tr.nextAll("tr").css('visibility', 'hidden');
//
// $node.addClass('collapsed');
// }
// });
}
$nodeCell.append($nodeDiv);
$nodeRow.append($nodeCell);
$tbody.append($nodeRow);
if ($childNodes.length > 0) {
// if it can be expanded then change the cursor
// $nodeDiv.css('cursor', 'pointer');
// recurse until leaves found (-1) or to the level specified
if (opts.depth == -1 || (level + 1 < opts.depth)) {
var $downLineRow = $("
");
var $downLineCell = $(" | ").attr("colspan", $childNodes.length * 2);
$downLineRow.append($downLineCell);
// draw the connecting line from the parent node to the horizontal line
$downLine = $("").addClass("line down");
$downLineCell.append($downLine);
$tbody.append($downLineRow);
// Draw the horizontal lines
var $linesRow = $("
");
$childNodes.each(function () {
var $left = $(" | ").addClass("line left top");
var $right = $(" | ").addClass("line right top");
$linesRow.append($left).append($right);
});
// horizontal line shouldn't extend beyond the first and last child branches
$linesRow.find("td:first")
.removeClass("top")
.end()
.find("td:last")
.removeClass("top");
$tbody.append($linesRow);
var $childNodesRow = $("
");
$childNodes.each(function () {
var $td = $(" | ");
$td.attr("colspan", 2);
// recurse through children lists and items
buildNode($(this), $td, level + 1, opts);
$childNodesRow.append($td);
});
}
$tbody.append($childNodesRow);
}
// any classes on the LI element get copied to the relevant node in the tree
// apart from the special 'collapsed' class, which collapses the sub-tree at this point
if ($node.attr('class') != undefined) {
var classList = $node.attr('class').split(/\s+/);
$.each(classList, function (index, item) {
if (item == 'collapsed') {
$nodeRow.nextAll('tr').css('visibility', 'hidden');
$nodeRow.removeClass('expanded');
$nodeRow.addClass('contracted');
$nodeDiv.css('cursor', 's-resize');
} else {
$nodeDiv.addClass(item);
}
});
}
if ($node.attr('link') && $node.attr('link') != '') {
let link = $node.attr('link');
$nodeDiv.html('' + $nodeDiv.text() + '
')
} else if ($node.attr('href') && $node.attr('href') != '') {
let href = $node.attr('href');
$nodeDiv.html('' + $nodeDiv.text() + '
')
}
$table.append($tbody);
$appendTo.append($table);
/* Prevent trees collapsing if a link inside a node is clicked */
$nodeDiv.children('a').click(function (e) {
e.stopPropagation();
});
};
})(jQuery);
//获取div下的表单属性
$.fn.serializeDiv = function() {
let json = {};
let inputs = $(this).find('input'),
selects = $(this).find('select'),
textareas = $(this).find('textarea');
let forms = inputs.add(selects).add(textareas);
$.each(forms, function(key, value) {
let name = forms.eq(key).attr('name'),
id = forms.eq(key).attr('id'),
val = forms.eq(key).val();
if (name) {
json[name] = val;
} else if (id) {
json[id] = val;
}
});
return json;
};
//获取div下的表单属性并转为json
$.fn.serializeDivJson = function() {
return JSON.stringify($(this).serializeDiv());
};