ember.js - Access child records in non-nested routes -


if have "organization" has many "clinics" , in app don't want routes nested, want access clinics on organization page , organization on clinic page, there special need do? using rails backend , if switch restadapter activemodeladapter , embed clinic ids works, know how standard restadapter.

router:

app.router.map ->   @resource 'organizations', ->   @resource 'organization', path: 'organization/:organization_id', ->    @resource 'clinics', -> 

organization template:

<h1>{{name}}</h1> <h2>clinics</h2>   {{#link-to 'clinics.new'}}new clinic{{/link-to}} <ul id="org-clinics">   {{#each clinics}}     <li>{{#link-to 'clinic' this}}{{name}}{{/link-to}}</li>   {{else}}     <strong>no clinics yet...</strong>   {{/each}} </ul> 

organization model:

app.organization = ds.model.extend   name: ds.attr 'string'   clinics: ds.hasmany 'clinic', async: true 

clinic template:

<h1>{{name}}</h1> <strong>organization: </strong>{{organization.name}} 

clinic model:

app.clinic = ds.model.extend   name: ds.attr 'string'   organization: ds.belongsto 'organization' 

depends on how want go it, can bind controller content super easily. example:

app.organizationscontroller = ember.arraycontroller.extend({   needs: ['clinics'],   clinics: null,   clinicsbinding, 'controllers.clinics.content',    clinicsupdated: function () {     // here because record updated   }.observes('clinics.@each.content') // bind properties });  app.clinicscontroller = ember.arraycontroller.extend({   needs: ['organizations'],   organizations: null,   organizationsbinding, 'controllers.organizations.content' }); 

you can acess them in templates, too. example, {{#each clinics}}

hope helps!


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -