我从这种性质的json响应中得到一个json数组
data {"success":true,"errorCode":0,"data":["kkkk-kkkk 1","oooo-ooooo 2"]}
kkkk-kkkk 1
oooo-ooooo 2
在角度脚本控制器中,我这样做是将数组推入html视图
else if (res.status == 200) {
$scope.partners = [];
var myJSON = res.data;
console.log("data" + JSON.stringify(res.data));
angular.forEach(myJSON, function (item) {
$scope.activities.push(item);
我想获取json数组以填充下拉菜单,这是一个挑战
<select ng-model="act" formcontrol class="ui fluid dropdown ng-untouched ng-pristine ng-valid" required>
<option ng-repeat="a in activities" value="{{a}}">{{a}}</option>
</select>
请协助
答案 0 :(得分:1)
实际上,您正在迭代错误的数组,而是在迭代对象。
因为在您的代码中:
console.log("data" + JSON.stringify(res.data));
会给你:
data {"success":true,"errorCode":0,"data":["kkkk-kkkk 1","oooo-ooooo 2"]}
因此,您需要将res.data.data
存储在myJSON
变量中,否则最好是直接在$scope.activities
中分配此数组:
$scope.activities = res.data.data;
在您的HTML中:
<select ng-model="act" formcontrol class="ui fluid dropdown ng-untouched ng-pristine ng-valid" ng-options="option for option in activities"required>
</select>
答案 1 :(得分:0)
使用 ng-options
ng-options="item as item for item in activities"