Search code examples
ember.jsember-datarelationship

Ember-Data Table from 2 sources with relationship


I think ember (data) is great, but I can't get my head around on how to create a html table which lists the company name and the person. What I'd like to get is:

Company Name
Microsoft           Steve Ballmer
Microsoft           Bill Gates
Apple                Steve Jobs

What i get is:

Company Name
Microsoft                    Steve Ballmer,Bill Gates
Apple                          Steve Jobs

I really would appreciate any help with this.

Here is jsbin:http://emberjs.jsbin.com/EnOqUxe/8/


Solution

  • You'll need to set up two each loops, the first iterating the companies, the second iterating the people within the company outside the table row loop.

    {{#each company in model}}
       {{#each person in company.people}}
       <tr>
          <td>{{ company.name }}</td>
          <td> {{ person.name }}</td>
       </tr>
      {{/each}}
    {{/each}}
    

    http://emberjs.jsbin.com/EnOqUxe/9/edit