将新节点添加到所需文件夹
add new node to desired folder
我正在尝试将节点添加到所需的文件夹,但不幸的是没有成功。这个想法很简单。通过单击按钮,用户可以看到模态,其中放置了一些参数,例如:节点的名称和描述值将动态地来自 http 请求,他也可以 select 文件夹,他想保存他的节点但由于某种原因节点是出现在每个父文件夹中,我找不到我的错误在哪里?
我已经重现了 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 =====
}
]);
}());
您在保存功能中的条件是错误的:
if ($scope.filters[i]) {
console.log("pass");
$scope.filters[i].children.push($scope.item)
}
$scope.filters[i] 总是 return 正确。您必须实施正确的条件才能在正确的文件夹中添加新项目
我分叉了你的 plunker 并更正了它以在模态上获取选定的节点并将其放入保存函数中:https://plnkr.co/edit/lReRGfPUkYAeRjs9K2Sv?p=preview
我正在尝试将节点添加到所需的文件夹,但不幸的是没有成功。这个想法很简单。通过单击按钮,用户可以看到模态,其中放置了一些参数,例如:节点的名称和描述值将动态地来自 http 请求,他也可以 select 文件夹,他想保存他的节点但由于某种原因节点是出现在每个父文件夹中,我找不到我的错误在哪里? 我已经重现了 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 =====
}
]);
}());
您在保存功能中的条件是错误的:
if ($scope.filters[i]) {
console.log("pass");
$scope.filters[i].children.push($scope.item)
}
$scope.filters[i] 总是 return 正确。您必须实施正确的条件才能在正确的文件夹中添加新项目
我分叉了你的 plunker 并更正了它以在模态上获取选定的节点并将其放入保存函数中:https://plnkr.co/edit/lReRGfPUkYAeRjs9K2Sv?p=preview