gpt4 book ai didi

javascript - 如何使用 Angular JS 在 html 下拉列表中显示 json 响应

转载 作者:行者123 更新时间:2023-12-03 06:44:10 25 4
gpt4 key购买 nike

我正在尝试使用 Angular JS 在 HTMl 的下拉列表中显示 JSON 响应。

我正在尝试在 html 中的机构下拉列表中调用“短名称”。有任何想法吗。提前致谢。

我的 JSON 代码

                       [{"id":1,"agencyCode":"006","agencyDescription":"null","shortName":"NJTA","cscId":1,"iagAgencyTypeId":4,"comments":"null","whoCreated":"admin","createdDate":"2016-06-13","whoUpdated":"admin","updatedDate":"2016-06-13"}]

HTML 代码

            <div class="dashboard_searcharea">
<div class="col-md-3" ng-repeat="shortname in agencies"> Agency :
<select class="text_field_style smallfield">
<option value="shortname"> agencies: {{agencies.shortname}} </option>
</select>
</div>
<div class="col-md-3"> Events :
<select class="text_field_style smallfield">
</select>
</div>

AngularJS

   Dashboard.controller('homeController',homeController); 
function homeController($scope,$location,$http) {
$scope.dt = new Date();
$scope.popup1 = {
opened: false
};
$scope.open1 = function() {
$scope.popup1.opened = true;
};

$http.get("http://localhost:8080/EtbosAdmin/agencies")
.success(function(response) {
$scope.metrics=response.series[0].shortname;

最佳答案

要达到您的预期结果,请按照以下步骤操作

1.在迭代中使用不同的名称和键值以避免混淆..为了测试,我在机构中使用了 JSON 和变量 x。

2.Key值为shortName,所以我们需要通过x.shortName来获取value。

我使用了 $scope.agcies 中的 JSON 进行测试

<div class="dashboard_searcharea">
<div class="col-md-3" ng-repeat="x in agencies"> Agency :
<select class="text_field_style smallfield">
<option value="shortname"> agencies: {{x.shortName}} </option>
</select>

Codepen URL - http://codepen.io/nagasai/pen/EyKqMB我创建的供引用

关于javascript - 如何使用 Angular JS 在 html 下拉列表中显示 json 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37823295/

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