我正在使用AngularJS。以下代码位于控制器中。我正在尝试使用其highlight属性设置为true的对象填充$ scope.highlighted。当对话框关闭时,我需要$ scope.highlighted清空。出于某种原因,我的closeDialog()函数中的$ scope.highlighted与我在getHighlighted()中传播的数组不同。我不知道这是否是AngularJS范围问题,JavaScript参考问题或其他什么?
$scope.highlighted = [];
$scope.closeDialog = function () {
console.log("closeDialog");
// Hide the dialog
$('#shared-list .modal').modal('hide');
// Clean up data for next shared list
console.log($scope.highlighted);
while ($scope.highlighted.length > 0) {
console.log("pop");
$scope.highlighted.pop();
}
console.log($scope.highlighted);
};
$scope.getHighlighted = function (root) {
var x, y;
for (x in root.CurrentItems) {
console.log(root.CurrentItems[x].ItemLabel + ": " + root.CurrentItems[x].highlight);
if (root.CurrentItems[x].highlight == true) {
console.log("push");
$scope.highlighted.push(root.CurrentItems[x]);
}
}
for (y in root.Folders) {
console.log(root.Folders[y].FolderLabel + ": " + root.Folders[y].highlight);
if (root.Folders[y].highlight == true) {
console.log("push");
$scope.highlighted.push(root.Folders[y]);
}
$scope.getHighlighted(root.Folders[y]);
}
};
$scope.showCreateSharedList = function () {
console.log("showShared");
console.log($scope.highlighted);
$scope.getHighlighted($scope.favorites);
console.log($scope.highlighted);
if ($scope.highlighted.length == 0) {
alert("Please select one or more items and/or folders to share.");
}
else {
$("#shared-list .modal").modal();
}
};