mardi 23 juin 2015

Ember.js how to update template rendering

I'm writing an application which structure like this.

/accounts
/account/{id}
/account/{id}/items
/account/{id}/item/{item_id}

page left put a sidebar list(accounts or items), put content at the right

router.js

this.resource('accounts', function() {
     this.resource('account', {path: '/:account_id'});
     this.resource('items', {path: '/:account_id/items'}, function() {
         this.resource('item', {path: '/:item_id'});
});

application.hbs

<div>{{outlet "sidebar_list"}}</div>

routes/accounts.js

export default Ember.Route.extend({
    model: function(){
        return this.store.find('customer');
    },
    renderTemplate: function() {
        this.render({ outlet: 'sidebar_list' });
    }
});

routes/account.js

export default Ember.Route.extend({
    model: function(params){
        return this.store.find('customer', params.account_id);
    }
});

routes/items.js

export default Ember.Route.extend({
    model: function(){
        return this.store.find('item');
    },
    renderTemplate: function() {
        this.render({ outlet: 'sidebar_list' });
    }
});

current I can visit account list(/accounts) page, which only show sidebar account list,
click an account item, the content will show at right page, and also show a item list belong this account.

visit /acounts/1

-----------------------------------------------------
|  account1  |    account information for account1     |
|  account2  |                                         |
|  account3  |                                         |
|            |      --------------------------         |
|            |              item 1                     |
|            |              item 6                     |
|            |                                         |
-----------------------------------------------------

and I can see the url for item 1 is /accounts/1/items/1, but click the link, nothing happened

  • why the url for account is accounts/1, not account/1?
  • why the item links at account page doesn't work, bug I can see the url when mouse over
  • if I directly visit /accounts/1/itmes/1, why only show the sidebar with account list
    • and it will get the data from RESTAPI url from /assets not /accounts/1/itmes, where I can change this?
    • how can I replace the account list, and show the items those belong the same account?

and how should I return data support the ember data to get this page /acount/2/item/4

 -----------------------------------------------------
|  account2  |    item information for item 4          |
|  --------  |                                         |
|   itme2    |                                         |
|   itme3    |                                         |
|   itme4    |                                         |
|            |                                         |
|            |                                         |
-----------------------------------------------------




Aucun commentaire:

Enregistrer un commentaire