ryantxu / ajax-panel

Ajax Panel Plugin for Grafana
MIT License
156 stars 154 forks source link

Iterating through response object #23

Closed codepattern closed 5 years ago

codepattern commented 5 years ago

Hi there,

Question - are you able to iterate (loop) through the response object using the angular template? Current our data looks like [ { "test": 1 }, { "test": 2 } ] and I want to display it using a template like:

{{ response.test }}

How can we perform this function?

johntdyer commented 5 years ago

+1

johntdyer commented 5 years ago

I am trying using some examples from the Angular docs but its not working

<div *ngFor="let hero of heroes">{{hero.name}}</div>
<app-hero-detail *ngFor="let hero of heroes" [hero]="hero"></app-hero-detail>

I would certainly appreciate any guidance you can provide

ryantxu commented 5 years ago

I'll update the example to something more interesting, but try:

<h2>Instance: {{ response.DEFAULT.instance_name }}</h2>

<div ng-repeat="(key, value) in response">
  <h5>{{key}}</h5>
  <pre>{{ value | json }}</pre>
</div>

Note this is angular 1.0 and any directive needs to be registered already in grafana. either though a plugin or native. I would not expect <app-hero-detail to do anything unless you did some other magic