0

I try to generate a table out of a JSON response

I know how to access the key but i do not find a way to get the value.

{{#each this}}
  {{@key}}
{{/each}}

Each key will be a row and the value will represent the content of the row (like in the below image)

The response is below :

this:

{  
   "DistributedQueue-0":{  
      "MessagesCurrentCount":"0",
      "MessagesPendingCount":"0",
      "MessagesReceivedCount":"0",
      "MessagesHighCount":"0",
      "ConsumersCurrentCount":"0",
      "ConsumersHighCount":"0",
      "ConsumersTotalCount":"0"
   },
   "PatientNotificationQueue":{  
      "MessagesCurrentCount":"0",
      "MessagesPendingCount":"0",
      "MessagesReceivedCount":"0",
      "MessagesHighCount":"0",
      "ConsumersCurrentCount":"0",
      "ConsumersHighCount":"0",
      "ConsumersTotalCount":"0"
   },
   "Topic-0":{  
      "MessagesCurrentCount":"0",
      "MessagesPendingCount":"0",
      "MessagesReceivedCount":"0",
      "MessagesHighCount":"0",
      "ConsumersCurrentCount":"0",
      "ConsumersHighCount":"0",
      "ConsumersTotalCount":"0"
   }
}

enter image description here

Cris
  • 4,947
  • 6
  • 44
  • 73

1 Answers1

1

The value of the element in each iteration is available as {{this}} inside a block like {{#each}}. So

{{#each this}} 
 {{@key}} = {{this}} 
{{/each}}

In your case it would render something like

KeyName: [object Object] 

since {{this}} now refers to the value, which is an object itself. You know how to iterate over an object using {{#each}} - you have just done that. Now you just need to use a nested {{#each}} loop! :)

{{#each this}}
  {{@key}}: 
    {{#each this}}
      {{@key}}: {{this}}
    {{/each}}
{{/each}}

Demo: http://jsfiddle.net/f5feae43/2/

pawel
  • 35,827
  • 7
  • 56
  • 53