【问题标题】:How to populate json data in drop down using angular js如何使用 Angular js 在下拉列表中填充 json 数据
【发布时间】:2017-02-02 12:14:18
【问题描述】:

我的html代码是

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

我的js代码是

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

我的json代码是:

data:["bank1","bank2",bank3"]

它在一行中获取所有数据。如何在下拉框中获取它?我希望数据作为列表下拉。

欢迎大家帮忙,谢谢。

【问题讨论】:

  • 下拉列表中某个人的数据?

标签: html angularjs json


【解决方案1】:

试试这个

<select ng-model="SelectedPerson" ng-options="person for person in persons.data"></select>

更新:

Working Demo

【讨论】:

  • @shilpa 我添加了工作演示。请检查一下
  • 如果你传递了正确的数组对象,那么它运行良好。
  • 我需要使用http请求通过api获取json数据,而不是手动,我的json格式是[{"status": "success", "data": ["bank1", "bank2","bank3",bank4"]} 我需要在下拉列表中获取“数据”@Ramesh Rajendran
  • 没有问题。这将是工作。这就是我在ng-options 中提到persons.data 的原因。
【解决方案2】:

这应该可行。

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

【讨论】:

    猜你喜欢
    • 2021-06-19
    • 1970-01-01
    • 1970-01-01
    • 2018-08-02
    • 2012-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多