angularjs中选择选项的嵌套列表

时间:2017-01-04 08:59:35

标签: javascript angularjs json ng-repeat

angularjs

绝对新手

我有json对象如下

data =
[{ company : "companyA", headOffice : "cityA", industry :"software", transactionCurency : "USD" , otherAspect :{numberofEmployees : "10000", public : "yes", listed : "NYSE"}},

{ company : "companyB", headOffice : "cityA", industry :"software", transactionCurency : "USD" , otherAspect :{numberofEmployees : "20000", public : "no", listed : "NA"}},

{ company : "companyC", headOffice : "cityB", industry :"Oil", transactionCurency : "EUR" , otherAspect :{numberofEmployees : "150000", public : "yes", listed : "LSE"}},
{ company : "companyD", headOffice : "cityX", industry :"manufactoring", transactionCurency : "YEN" , otherAspect :{numberofEmployees : "30000", public : "yes", listed : "TSE"}
},

{ company : "companyE", headOffice : "cityB", industry :"Auto", transactionCurency : "EUR" , otherAspect :{numberofEmployees : "330000", public : "no", listed : "NA"}}];

我想在“otherAspect”内部列表的基础上创建下拉列表.. 如numberOfEmployees = {3000,330000,1000,20000},列出=“纽约证券交易所,NA,LSE,TSE”同样。

我尝试过使用ng-repeat但是对于每个对象都创建了一个下拉列表,因此我有数百个下拉。

正如我所说,我是这个论坛的新手以及angularjs我不知道我需要提供什么信息。 感谢

2 个答案:

答案 0 :(得分:0)

您可以使用ng-options执行此操作:

<select ng-model="aspect" ng-options="d.otherAspect.listed for d in data"></select>

Demo on JSFiddle.

答案 1 :(得分:0)

试试这个

<强> HTML:

  async geolocate() {
    return new Promise((resolve, reject) => {

      navigator.geolocation.getCurrentPosition(
        (position) => {
          resolve(position);
        },
        (err) => {
          reject(err);
        },
        {enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
      );
    });
  }

<强>使用Javascript:

<div ng-app="myApp">
<div ng-controller="MyCtrl">
<select ng-model="aspect" ng-options="d.otherAspect.listed for d in data">
</select>
<br/>Selected: {{aspect}}
</div>
</div>