javascript - AngularJS ng-repeat 不适用于选择选项
问题描述
我的http
部分它工作它得到的值没有问题但是当我在选择选项上使用它们时它没有显示它在检查中显示它显示所有值
$http({
method: "GET",
url: "php/home_page.php"
}).success(function(result) {
$scope.populars = result;
});
<select data-placeholder="Choose Location" >
<option ng-repeat="reserve in populars"> {{reserve.name}}</option>
</select>
解决方案
您正在 $scope.populars 上保存 $http 响应对象,而不是您在 html 片段中所期望的对象数组。
我建议:
$http({
// request info
}).success(function(response) {
$scope.populars = response.data;
});
假设您的 API 响应的数据具有以下形式:
data = [
{
name: "data",
// other object members
}
]
推荐阅读
- python - 不使用按钮单击更新串行数据
- amazon-web-services - Dynamo DB 中的 AWS AppSync 简单 graphql 解析器无法正常工作,这让我发疯
- redux - 初始化存储时不触发 ROOT_EFFECTS_INIT
- r - 为什么在用 na.locf 填充 NA 后 tbf 仍然分组?
- python - Python assert - 用一行报告列表中不存在文件的最佳方法
- react-native - 在 ReactNative 的屏幕中何处进行 API 调用?
- java - Netbeans - 在java源文件中查找导入类的使用成员
- python - 没有外键检查的 Pandas to_sql
- powerbi - PowerBI - 匹配另一个表中的值
- c# - 如何将子类的对象作为函数参数传递?