使用Angular Chosen允许多国选择下拉。 https://github.com/localytics/angular-chosen
我收到错误
" a.forEach不是一个功能"
无论您选择了一个,两个还是零选项,都会发生此错误。
我看过这篇文章
Getting a a.foreach is not a function error
但是我选择的值已经是一个数组,所以它不会在这个问题上提供任何帮助。
这是我的HTML
<li class="form-row">
<span class="label">
<label for="nation">Nationality</label>:
</span>
<div class="field country">
<select
chosen
multiple
ng-model='person.nation'
ng-options='c.name as c.name for c in countries'
id="nation"
data-select-max="2"
data-token="Nationalities"
data-placeholder="- Select your nationalities -">
</select>
</div>
</li>
我的选项($ scope.countries)看起来像
[
{ id="1", name="United States"},
{ id="2185", name="Afghanistan"},
etc....
]
非常感谢任何建议。
答案 0 :(得分:2)
应该像这样指定数组对象的属性:X <- matrix(stats::rnorm(2000), ncol = 2)
chull(X)
plot(X[,1],X[,2])
points(X[chull(X),1],X[chull(X),2],col=2,pch=19)
,而不是id:"1", name:"United States"
。用冒号(:)替换等号(=)。
此外,您应该以下列方式使用forEach功能:
id="1"
而不是数组的函数:angular.forEach($scope.countries, function(key, value){
// your code here
});