显示来自服务器的JSON响应,以便在Ember CLI中处理条形模板

时间:2015-06-04 07:49:11

标签: json ruby-on-rails-4 ember.js ember-data ember-cli

来自服务器的我的Json API

我从服务器获得此API响应。如何在模板中显示JSON。

{
  past_bills: [
    {
      id:1,
      Status: "Success",
      Count: 3,
      Subscribers: [
        {
          SubscriberID: 100168,
          Count: 3,
          Invoices: [
            {
              InvoiceYear: "2014",
              InvoiceMonth: "1",
              Link: "https://invoices.test.com/A6034C05-C9BE-4A1A-9741-1E07B04F47BB/100168_3935_2014_02_invoice.pdf"
            },
            {
              InvoiceYear: "2014",
              InvoiceMonth: "2",
              Link: "https://invoices.test.com/00168/5C00ABAE-524D-4D86-A927-610646CEB56E/100168_4799_2014_03_invoice.pdf"
            },
            {
              InvoiceYear: "2014",
              InvoiceMonth: "3",
              Link: "https://invoices.test.com/100168/9533058F-2348-4D67-A1D3-187BC86CF40F/100168_6054_2014_04_invoice.pdf"
            }
          ]
        }
      ]
    }
  ]
}

我的路线

export default Ember.Route.extend({
  model: function(params) {
    this.store.find('past-bill',params);
  }
});

我的模板

<table>
{{#each item in model}}
    <tr><td>Hiii</td></tr>
    {{/each}}
</table>

我的模型文件

import DS from 'ember-data';

export default DS.Model.extend({
    Status: DS.attr(),
    Count: DS.attr(),
    Subscribers: DS.attr()
});

我想将响应json显示给模板。我试过,但我没有在模板中得到结果。

1 个答案:

答案 0 :(得分:0)

{{#each item in  model}}
        {{#each sub in item.Subscribers}}
            {{#each invoice in sub.Invoices}}
                <tr role="row">
                <td>{{invoice.InvoiceMonth}}</td>
                <td>{{invoice.InvoiceYear}}</td>
                <td><a {{bind-attr href='invoice.Link'}} target="_blank">View Bill</a> {{!invoice.Link}}</td>
                </tr>
                {{/each}}
        {{/each}}
    {{/each}}