Here I'm posting relevant code, any help appreciated.
I have a nested route implementation:
this.resource('users', function() {
this.resource('user', {path:':user_id'});
}
I have template defined:
<script type="text/x-handlebars" id="users">
<ul>
{{#each}}
<li>{{#link-to 'user' this}} {{name}} edit {{/link-to}}</li>
{{/each}}
</ul>
{{outlet}}
</script>
And another template for id="user" containing simple input (edit) for modifying the user name.
When I click on the user, an edit form (based on UserRoute) comes up in the outlet, the corresponding user link becomes active state.
When I edit the corresponding user properties, the change reflects the corresponding user name in the list of users. All this setup works fine.
However, when I reload/refresh the page, based on the uri path, the link-to does not become active even though uri path corresponds correctly and also when I edit the user, it does not reflect the corresponding user object in the list. Seems at that point it's loosely coupled, ie: the object in the list does not correspond to the object selected which the router routes to based on uri path.
I'm using my own custom adapter (without ember-data) In the UsersRoute I have model hook defined:
return this.adapter.all(); //ajax request
And in UserRoute I have model hook defined:
return this.adapter.find(params.user_id); //ajax request
I'm relatively new to Ember but this still seems trivial to me that it's not working as expected when I reload the page, the link-to and bindings should be "in sync". Unless Ember does not base it on the ID given uri path (ie: #/users/46) but on the object itself, and it would make sense that just because I return an object with the same properties and id, does not mean it's the same corresponding to the object loaded from the UsersRoute (uses ArrayController). Without a messy solution overriding the setupController, calling the parent controller, getting corresponding model etc...I'm not sure of an elegant way to get around it. Passing id instead of "this" in the link-to causes similar problems as well.
Aucun commentaire:
Enregistrer un commentaire