1
votes

In the Ember guide, the partial seem to magically get author's firstname and lastname attributes.

But it is failing for my try, see my jsbin where I have two models: Organization (with "name" and "description") and Member (with "name"). Organizations is displayed successfully, but I'm failing to display the Members.

  <script type="text/x-handlebars" id="organization">
      ...
      {{ partial "member" }}
  </script>

  <script type="text/x-handlebars" id="_member">
     Here are the Members:
     <ul>
      {{#each member}}
        <li>{{member.name}}</li>
      {{/each}}
     </ul>
  </script>
2

2 Answers

1
votes

I've fixed it here: http://jsbin.com/iwiruw/239/edit

Let me know if you have any questions about how it works.

Edward

0
votes

Adding to what Edward said as he didn't have time to complete his answer:

I shouldn't use a partial in this case. The guide says that {{partial}} does not change context or scope. It simply drops the given template into place with the current scope. This means there is no route jumping for partials. So partials do not have routes, like the App.Router.map ... this.resource()... defined.

This is a simplified version of Edward's jsbin, taking out the unnecessary partial.

The key to displaying both the org model and the member model

  Here are the Orgs:
  <ul>
  {{#each model}}
    <li>{{name}} - {{description}}</li>
  {{/each}}
  </ul>

  Here are the Members:
  {{#each member in members}}
    <li>{{member.name}}</li>
  {{/each}}

is in the controller:

App.OrganizationRoute = Ember.Route.extend({
  model: function() {
    return App.Org.find();
  },
  setupController: function(controller, model) {
    controller.set('members', App.Member.find());
  }
});