0

I have the following JSON file to read and I want to only display some particular keys I want from the JSON.

[
  {
     "recommendation_id": "cuhwbchuwbcuhw-ccnahcbhb-12",
     "title": "hellow world",
     "content": "Hello angular",
     "name": "John",
     "home": "USA"
  },
  {
     "recommendation_id": "cuhwcacabchuwbw-ccnahcbhb-32",
     "title": "ng-show",
     "content": "ng-show is amazing",
     "name": "Google",
     "home": "USA"
  },
  ......
  {
     "recommendation_id": "guwqiwu212wbcuhw-ccnahcbhb-12",
     "title": "Awesome",
     "content": "Hello Awesome",
     "name": "Mike",
     "home": "Canada"
  }
]

Here is what I use to access the header for my table using Jade.

table(id="allRecommendations")
  thead
    tr
      th(ng-repeat='(key, value) in recommendationsAll[1]') {{key}}

And the output is

recommendation_id     title    content   name    home

But I only want the first three items, which should display like the following:

recommendation_id     title    content

So, what do I miss on my filter? I am interested in getting the object properties not my property details. How do I filter to show particular JSON properties?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
zihaow
  • 312
  • 2
  • 9
  • 23
  • fairly trivial to get rid of the ng-repeat and manually create three ``. Also, what filter are you talking about, there is none shown in your code? – charlietfl Oct 22 '15 at 21:31
  • 1
    Possible duplicate of [ngRepeat - limiting number of displayed results](http://stackoverflow.com/questions/17643361/ngrepeat-limiting-number-of-displayed-results) – isherwood Oct 22 '15 at 21:33
  • `ng-repeat='… | limitTo:3'` – laggingreflex Oct 24 '15 at 10:05

1 Answers1

-1

This will solve the problem.

table(id="allRecommendations")
  thead
    tr
      th(ng-repeat="(key, value) in recommendationsAll[1]", ng-show="key == 'recommendation_id' || key == 'title' || key == 'content' " ) {{key}}
zihaow
  • 312
  • 2
  • 9
  • 23