gpt4 book ai didi

javascript - Angularjs 多选 : Cannot read property 'length' of undefined

转载 作者:行者123 更新时间:2023-11-29 20:58:18 25 4
gpt4 key购买 nike

我尝试了很多变体,但似乎没有任何效果。

我收到以下错误:

TypeError: Cannot read property 'length' of undefined
at select.js:1560
at m.$broadcast (angular.js:18487)
at Object.ctrl.select (select.js:673)
at fn (eval at compile (angular.js:15358), <anonymous>:4:453)
at e (angular.js:26994)
at b.$eval (angular.js:18161)
at b.$apply (angular.js:18261)
at HTMLDivElement.<anonymous> (angular.js:26999)
at HTMLDivElement.dispatch (jquery-3.2.1.min.js:3)
at HTMLDivElement.q.handle (jquery-3.2.1.min.js:3)

我在 HTML 部分的代码是:

<label for="addRecipient" class="bold">Additional Recipients:</label>
<ui-select multiple ng-model="addRecipient.selection" theme="bootstrap" title="Choose Recipients" class="multipleSelect">
<ui-select-match placeholder="Select Additional Recipients...">{{$item.name}}</ui-select-match>
<ui-select-choices repeat="additional in addRecipients | filter:$select.search">
{{additional.name}}
</ui-select-choices>
</ui-select>

在我的 Controller 中:

$scope.addRecipient = {}; 
$scope.addRecipients = [];
$.each(success.data.d.results, function (ind, val) {
$scope.addRecipients.push({'name': val.Title, 'email':val.Email});
});

我可以在我的选择中看到要选择的选项,但是每次我点击任何选项时,我都会收到该错误。这是显示来自 success.data.d.results 的信息的下拉列表:

dropdown

最佳答案

这就是我的代码现在的样子,并且可以正常工作。感谢@NTP 的提示!

<label for="addRecipient" class="bold">Additional Recipients:</label>
<ui-select multiple ng-model="addRecipient.selected" theme="bootstrap" title="Choose Recipients" class="multipleSelect">
<ui-select-match placeholder="Select Additional Recipients...">{{$item.Title}}</ui-select-match>
<ui-select-choices repeat="additional in addRecipients | filter:$select.search">
{{additional.Title}}
</ui-select-choices>

在 Controller 中:

$scope.addRecipient = {}; 
$scope.addRecipients = [];

下拉值:

$scope.addRecipients = success.data.d.results;

获取选定的值:

//add Recipient
var addRecipients;
if ($scope.addRecipient.selected && $scope.addRecipient.selected !='undefined'){
things = [];
console.log($scope.addRecipient.selected);
for (var key in $scope.addRecipient.selected) {
if (key < $scope.addRecipient.selected.length) {
things.push($scope.addRecipient.selected[key].Email) ;
}
}
addRecipients = things;
}

关于javascript - Angularjs 多选 : Cannot read property 'length' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48062595/

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