【发布时间】:2018-06-12 06:07:22
【问题描述】:
我尝试了很多变化,但似乎没有任何效果。
我收到以下错误:
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>
在我的控制器中:
$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 信息的下拉列表:
【问题讨论】:
-
这意味着你的数组是空的
-
这不是您的完整控制器,我的假设是 success.data.d.results 是空的,因此您的 $.each 没有迭代
-
拜托,你能分享控制器,指令等吗?
-
数组有值。我在下拉列表中得到结果。我将在我的帖子中添加一张图片。
-
现在一切正常。我很高兴我们找到了解决此类问题的方法。
标签: javascript angularjs select multiple-select