ng-options:如何访问在键或值中没有索引的对象中的位置(索引)

时间:2016-05-21 10:57:27

标签: javascript angularjs json indexing angularjs-ng-options

我有一个JSON obj。如下:

[
   {"Title":"x", "Type":"y", "Desc":"First Description"},
   {"Title":"r", "Type":"q", "Desc":"Second Description"}
]

我希望在此obj中包含一个包含标题的下拉列表(使用ng-options)。然后,我想在对象中使用所选标​​题的索引。 (想象一下,该对象将被用作数组(称为myArray),就像 user194715 回答here)一样 例如:

var type = myArray[selectedIndex].Type;
var description= myArray[selectedIndex].Desc;

在这种情况下如何访问索引?

1 个答案:

答案 0 :(得分:0)

试试这个



export class DataUriValueConverter {
  toView(value, mimeType) {
    return `data:${mimeType};base64,${value}`;
  }
}

var app = angular.module("app",  []);

app.controller('mainCtrl', function($scope){
  $scope.myArray =
        [
          {"Title":"x", "Type":"y", "Desc":"First Description"},
          {"Title":"r", "Type":"q", "Desc":"Second Description"}
        ];
});