首页 > 解决方案 > 如何在不知道数据模型的情况下显示对象数组

问题描述

我有一个对象数组,这是我的对象结构:

[{
  "_index": "bank",
  "_type": "account",
  "_id": "25",
  "_score": 1,
  "_source": {
    "account_number": 25,
    "balance": 40540,
    "firstname": "Virginia",
    "lastname": "Ayala",
    "age": 39
  }
}, ... ]

我需要消除_index_type_id_score(仅显示_source),并且我想在每个键之前显示一个包含值的输入:

帐号[25]

余额[40540] ......

<tbody>
    <tr ng-repeat="row in ctrl_hits.data | limitTo: row._index+row._type+row._id+row._score">
      <td> {{row.key}} : 
          <input type="text"
          ng-value="row.value">
      </td>
    </tr>
</tbody>

NW:我知道,我正在编写愚蠢的代码,仅出于一个原因,来解释我的需求。

标签: angularjsangularjs-ng-repeat

解决方案


ng-repeat="(key,value) in row._source"

<tbody>
    <tr ng-repeat="row in ctrl_hits.data | limitTo: row._index+row._type+row._id+row._score">
      <td ng-repeat="(key,value) in row._source">
          {{key}} : 
          <input type="text" ng-model="row._source[key]">
      </td>
    </tr>
</tbody>

推荐阅读