AngularJs选择添加选项 [英] AngularJs select add option
本文介绍了AngularJs选择添加选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我angularjs和选择选项收集工作。如果我在HTML中的选项标签添加的所有作品不错。但如果我尝试从角添加的项目它不工作。
I work with angularjs and select options collection. If I added in html option tags all works good. But if i try added item from angular it is not working.
我的code:
<div ng-controller="statisticsTableController">
<select ng-model="publishersdata"
ng-options="s for s in publishersdata"
chosen option="publishersdata">
</select>
</div>
和AngularJs code:
and AngularJs code:
function statisticsTableController($scope, $http) {
var publishersArray = [];
$http.get('/api/getAllItems').success(function(data) {
angular.forEach(data, function(data) {
publishersArray.push(data.Name);
});
});
this.publishersdata = publishersArray;
//...
}
为什么它不工作?而如何解决?
Why it is not working? And how to fix it?
更新
在变化:
function statisticsTableController($scope, $http) {
var publishersArray = [];
$http.get('/api/getAllItems')
.success(function (data) {
angular.forEach(data, function (data) {
publishersArray.push(data.Name);
});
});
$scope.publishersdata = publishersArray;
//...
}
HTML
<div ng-controller="statisticsTableController">
<select multiple
ng-model="publishersdata"
ng-options="s for s in publishersdata"
chosen option="publishersdata">
</select>
</div>
它不能正常工作
推荐答案
试code,而不是数据的使用价值中的foreach参数
try the code instead of data use value in argument of foreach
angular.forEach(data, function (value) {
publishersArray.push(value.Name);
});
这篇关于AngularJs选择添加选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文