gpt4 book ai didi

javascript - 使用 AngularJS.js 获取下拉列表中的 JSON 数据?

转载 作者:行者123 更新时间:2023-11-28 05:06:24 24 4
gpt4 key购买 nike

这是我的 HTML 代码

<body ng-app="mainApp">
<div ng-controller="myController">
<select>
<option ng-repeat="person in persons">{{ person.data }}</option>
</select>
</div>
</body>

这是我的 JavaScript 代码

var app = angular.module("mainApp", []);
app.controller("myController", function($scope, $http) {
$http.get("JSON URL")
.success(function(response) {
$scope.persons = response.data;
});
});

我的 JSON URL 的格式是[{"status": "success", "data": ["bank1","bank2","bank3"]}],我只想要下拉列表中的“数据”列表,JSON数据中的银行太多,如何使用选择和选项?

最佳答案

你可以做到这一点,

Controller :

app.controller("dobController", ["$scope", "$http",
function($scope, $http) {
$http.get("test.json").then(function(response) {
$scope.data = response.data[0].data;
console.log($scope.data);
})
}

]);

HTML:

<body ng-controller="dobController">
<select class="form-control" id="selection" ng-model="currentSelected" ng-options="selection as selection for selection in data"></select>
</body>

<强> DEMO

关于javascript - 使用 AngularJS.js 获取下拉列表中的 JSON 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41711413/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com