1

I've an array of objects and this is my object structure:

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

I need to eliminate _index, _type, _id, _score (just displaying _source) and I would like to display ahead of each key an input which contains the value:

account_number: [25]

balance: [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: I know, I'm writing stupid code, just for one reason, to explain my needs.

2 Answers 2

1

Do 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>
Sign up to request clarification or add additional context in comments.

Comments

0

At first you must use map function for arrays to eliminate unuseful data(_index,_type,etc) and keep the _source.

if x is your array of objects then ctrl_hits.data will have an array with the _source object of your previous data.

ctrl_hits.data=x.map(function(e){
    return e._source;
})

Then at your html

 <tbody>
        <tr ng-repeat="item in ctrl_hits.data">
          <td ng-repeat=(key,value) in item>              
            {{key}} : <input type="text" ng-model="value"/>
          </td>
        </tr>
 </tbody>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.