简体   繁体   English

如何使用Angular JS在HTML下拉列表中显示JSON响应

[英]How to show json response in html drop down list using angular js

I'm trying to display a JSON response in a drop down list in the HTMl using Angular JS. 我正在尝试使用Angular JS在HTMl的下拉列表中显示JSON响应。

I'm trying to call "short name" in the agency drop down list in html. 我正在尝试在html的代理商下拉列表中调用“短名称”。 Any ideas. 有任何想法吗。 Thanks in advance. 提前致谢。

My JSON code 我的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 CODE 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>

Angular JS 角JS

   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; 

To achieve your expected result please follow below steps 为了达到预期效果,请按照以下步骤操作

1.In Iteration use different name then the key value to avoid confusion ..for testing i have used JSON and variable x in agencies. 1.在Iteration中使用不同的名称,然后使用键值,以避免混淆..为了进行测试,我在代理机构中使用了JSON和变量x。

2.Key value is shortName , so we need to get value by x.shortName. 2.Key的值是shortName,所以我们需要通过x.shortName来获取值。

I have used the JSON in $scope.agencies for testing 我已经在$ scope.agencies中使用了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 which i have created for reference Codepen网址- http://codepen.io/nagasai/pen/EyKqMB这都是我为参考创建

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用jQuery提取和添加作为AJAX响应的JSON数据到HTML select下拉列表? - How to extract and add the JSON data received as a AJAX response to the HTML select drop down using jQuery? 如何绑定json数据以在js下拉列表? - how to bind json data to drop down in angular js? 使用JSON数据在HTML中填充下拉列表 - Populate drop-down list in HTML using JSON data 如何在angular js中使用自定义json数据格式创建下拉列表 - How to create a drop down with custom json data format in angular js 使用AngularJS.js在下拉列表中获取JSON数据? - Get JSON data in drop down list using AngularJS.js? 如何在HTML中隐藏/显示下拉列表内容 - How to hide/show drop down list content in HTML 如何将嵌套的 json 数据填充到 angular 材料下拉列表 - How to populate nested json data to angular material drop down list 如何使用 Angular.js/Javascript 在现有下拉列表中添加静态值 - How to add static value in existing drop down list using Angular.js/Javascript 如何使用Angular.JS在下拉列表中绑定选项的值和文本 - How to bind both the option's value and text in a drop down list using Angular.JS 如何使用HTML / JS实现“人类”日期范围选择下拉列表? (今天,昨天,上周…) - How to implement a 'human' date range selection drop down list using HTML/JS? (Today, Yesterday, Last Week…)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM