我尝试将节点添加到所需的文件夹,但遗憾的是没有成功。这个想法很简单。通过单击按钮,用户可以看到模式,其中放置了一些参数,例如:节点的名称和描述,该值将来自http请求,也可以选择要保存其节点的文件夹,但由于某种原因,节点出现在每个父节点中文件夹,我无法找到我的错误在哪里? 我已经用我的问题复制了plunker
我的代码:
(function() {
app.controller('HomeCtrl', ["$scope", "$rootScope", "$http", '$interval', '$q', "$log", "$routeParams", "$location", "$uibModal",
function($scope, $rootScope, $http, $interval, $q, $log, $routeParams, $location, $uibModal) {
$scope.tree_core = {
multiple: false, // disable multiple node selection
check_callback: function(operation, node, node_parent, node_position, more) {
// operation can be 'create_node', 'rename_node', 'delete_node', 'move_node' or 'copy_node'
// in case of 'rename_node' node_position is filled with the new node name
if (operation === 'move_node') {
return false; // disallow all dnd operations
}
return true; // allow all other operations
}
};
$scope.contextMenu = custom.contextMenu;
// *** Begin Callback Functions for Tree ***
// Describe callback function that to all necessary variables related with Jstree
$scope.callback = function(e, data) {
// ===== Click event on node for Industry =====
for (var i = 0; i < data.selected.length; i++) {
var parentNodeId = data.instance.get_node(data.selected[i]).parent;
var parentNodeText = data.instance.get_node(parentNodeId).text;
$scope.node = data.instance.get_node(data.selected[i]).text;
$scope.path = data.instance.get_path(data.node, ' / ');
}
};
// Declared initial folder
$scope.filters = custom.sharedFilter;
$scope.open = function() {
var modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
templateUrl: 'modal.html',
controller: 'EventFilterCtrl',
size: 'md',
resolve: {
items: function() {
return $scope.filters;
}
}
});
modalInstance.result.then(function(selectedItem) {
$scope.selected = selectedItem;
}, function() {
$log.info('Modal dismissed at: ' + new Date());
});
};
// Storing variable in localstorage later will moved to DB
// Data based on ui-modal and ui-grid callback functions
$rootScope.saveFilter = function() {
var $saveForm = $('#filter-save-form');
var filterName = $saveForm.find('#filter-save-name').val();
var filterDescription = $saveForm.find('#filter-save-description').val();
$scope.item = {
"text": filterName,
"description": filterDescription,
"value": Date.now(),
};
var i = 0;
for (i; i < $scope.filters.length; i++) {
if ($scope.filters[i]) {
console.log("pass");
$scope.filters[i].children.push($scope.item)
}
}
};
// ==== End Build Left Bar =====
}
]);
}());
答案 0 :(得分:1)
保存功能的条件错误:
if ($scope.filters[i]) {
console.log("pass");
$scope.filters[i].children.push($scope.item)
}
$ scope.filters [i]总是返回true。您必须实现正确的条件才能在正确的文件夹中添加新项目
我将您的plunker分叉并更正它以获取模态上的选定节点并将其置于保存功能中:https://plnkr.co/edit/lReRGfPUkYAeRjs9K2Sv?p=preview