试图用下拉列表中的数据填充一个下拉列表,该列表是通过http.get api以角度获取的,下面的代码返回$$ state对象。我在遍历$$ state对象并创建一个新对象时遇到了麻烦,该对象将在我的视图中用于列出下拉菜单的选项。感谢您的任何帮助
$scope.getdataList= function () {
return $http.get("/api/v1/colorList/getcolor")
.then(function (response) {
return JSON.stringify(response.data);
});
};
$scope.dataList = $scope.getdataList();
/ api / v1 / colorList / getcolor生成xml
<ColorsResponse>
<Colors>
<color>
<AllowCaseUnderCase>false</AllowCaseUnderCase>
<ColorId>1</ColorId>
<ColorSettingId>5</ColorSettingId>
<ColorName>Red</ColorName>
<Name>Redco</Name>
<RolesEnabled>false</RolesEnabled>
<ShortName>RC</ShortName>
</color>
</Colors>
</ColorsResponse>
$scope.myData = [];
$scope.colorObj = {};
angular.forEach($scope.dataList , function (key,value) {
angular.forEach(value, function (k, v) {
colorObj.Id= $scope.dataList['ColorId'];
colorObj.settingId = $scope.dataList['colorSettingId'];
colorObj.Name = $scope.dataList['name'];
});
myData.push(colorObj);
});
如果我执行console.log($ scope.dataList),则会创建以下对象
$$state:
status: 1
value: "{
"Colors":[{
"ColorId":1,
"name":"Redco",
"shortName":"Rc",
"allowCaseUnderCase":false,
"rolesEnabled":false,
"colorName":"Red",
"colorSettingId":5
}],
"ErrorMessages":[],
"InformationMessages":[],
"Success":true
}"
在我看来
<select >
<option ng-repeat="colorItem in myData" value="{{colorItem.Id}}"
ng-change="fetchUser( colorItem.Id , colorItem.settingId )">
{{colorItem.Name}}
</option>
</select>