我使用插件Angular UI Tree:
http://angular-ui-tree.github.io/angular-ui-tree/#/basic-example
<a class="pull-right btn btn-primary btn-xs" data-nodrag="" ng-click="newSubItem(this)" style="margin-right: 8px;"><span class="glyphicon glyphicon-plus"></span></a>
我使用此代码:
$scope.newSubItem = function (scope) {
var nodeData = scope.$modelValue;
var arrr_nodes = [];
angular.forEach(nodeData.nodes, function (value) {
arrr_nodes.push(arrr_nodes);
});
var total_nodes = nodeData.nodes.length;
var prefix_increment = total_nodes + 1;
nodeData.nodes.push({
id: nodeData.id + prefix_increment,
prefix: nodeData.prefix + "_" + prefix_increment,
title: nodeData.title + '.' + (nodeData.nodes.length + 1),
value: nodeData.value,
type: nodeData.type,
nodes: []
});
};