mercredi 15 avril 2015

Ember Nested Views in Master Detail UI

I'm trying to create a master/detail UI with Ember that is a little different from the typical scenario shown in most guides/demos I have viewed. In my case, I want to have a list of users (loaded from /patients) where each user element has its own dedicated detail panel that is populated (with additional details loaded from /patients/:id) and rendered when an element/button is clicked in the master view. The typical master/detail demo online renders the detail for any element in a list of elements into a single detail element somewhere on the page.


Router:



App.Router.map(function() {
this.resource('patients', function() {
this.resource('patient', { path: ':patient_id' });
});
});


Models:



App.PatientsRoute = Ember.Route.extend({
model: function() {
return this.store.find('patient');
}
});

App.PatientRoute = Ember.Route.extend({
model: function() {
return this.store.find('patient', 1);
}
});


Templates:



<script type="text/x-handlebars">
{{outlet}}
</script>

<script type="text/x-handlebars" id="patients">
{{#each item in model}}
{{#link-to "patient" item}}show detail{{/link-to}}
...info....
{{outlet}} <--where "patient" detail panel goes
{{/each}}

<script type="text/x-handlebars" id="patient">
....detail info....
</script>


This retrieves and renders the list of patients. But, when any detail link is clicked, all of the child detail panels render for every patient in the list. How do I just have the child 'patient' detail show/render for the clicked parent? Would it be better to use an action vs. #link-to?


Aucun commentaire:

Enregistrer un commentaire