gpt4 book ai didi

javascript - AngularJS ng-options 错误 : Can't copy! 不支持制作 Window 或 Scope 实例的副本

转载 作者:行者123 更新时间:2023-12-01 15:47:49 25 4
gpt4 key购买 nike

我使用的是 AngularJS 1.5.11 版。

我使用 ng-options 创建了一个选择(多个)元素:

<select multiple class="form-control" ng-model="vm.selectedBuildings" ng-options="building as building.name for building in vm.buildings track by building.id"></select>

每当我选择其中一个元素,而不是将元素推送到 selectedBuildings 数组时,我会收到错误消息:“无法复制!不支持制作 Window 或 Scope 实例的副本。”

我花了无数个小时试图弄清楚这一点。有人请帮忙!

Controller 相关代码
var self = this;
self.selectedBuildings = [];

function getBuildings() {
buildingService.getBuildings(campusId, function (buildings) {
// retrieve buildings from API
self.buildings = buildings;

// etc, etc
});
}

// I am using a Bootstrap modal to display some information.
// I have multiple structures but only one modal, so when the
// modal is shown, I dynamically populate self.selectedBuildings.
$("#modal-lot").on("shown.bs.modal", function () {
// etc, etc
var lot = self.lots[self.structureToUpdate];

for (var i = 0; i < self.buildings.length; i++) {
let building = self.buildings[i];
let index = lot.buildings.indexOf(building.id);
if (index > -1) {
self.selectedBuildings.push(building);
}
}
// etc, etc

$scope.$apply();
});

// When the modal is hidden, clear the array
$("#modal-lot").on("hidden.bs.modal", function () {
self.selectedBuildings = [];
});

错误信息
Error: [ng:cpws] Can't copy! Making copies of Window or Scope instances is not supported.
http://errors.angularjs.org/1.5.11/ng/cpws
http://***/static/bower_components/angular/angular.js:68:32
copyElement@http://***/static/bower_components/angular/angular.js:961:21
copyRecurse@http://***/static/bower_components/angular/angular.js:933:41
copyRecurse@http://***/static/bower_components/angular/angular.js:933:41
copyRecurse@http://***/static/bower_components/angular/angular.js:933:41
copyRecurse@http://***/static/bower_components/angular/angular.js:933:41
copyRecurse@http://***/static/bower_components/angular/angular.js:922:37
copyRecurse@http://***/static/bower_components/angular/angular.js:933:41
copyRecurse@http://***/static/bower_components/angular/angular.js:933:41
copyRecurse@http://***/static/bower_components/angular/angular.js:933:41
copyRecurse@http://***/static/bower_components/angular/angular.js:922:37
copyRecurse@http://***/static/bower_components/angular/angular.js:933:41
http://***/static/bower_components/angular/angular.js:29665:91
forEach@http://***/static/bower_components/angular/angular.js:325:24
readNgOptionsMultiple@http://***/static/bower_components/angular/angular.js:29663:18
http://***/static/bower_components/angular/angular.js:31995:57
$apply@http://***/static/bower_components/angular/angular.js:18094:30
http://***/static/bower_components/angular/angular.js:31994:21
dispatch@https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js:3:10320

最佳答案

尝试将 self.selectedBuildings 初始化为 Controller 开头的数组,如下所示

self.selectedBuildings = [];

关于javascript - AngularJS ng-options 错误 : Can't copy! 不支持制作 Window 或 Scope 实例的副本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42991024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com