Tuesday, 15 June 2010

ember.js - Nested Route Firing from links, not from URL change -



ember.js - Nested Route Firing from links, not from URL change -

i working on basic ember.js application , little confused behavior. have routes this:

this.resource('campaigns', { path: '/campaigns'}, function() { this.route('new', { path: '/new' }); this.route('campaign', { path: '/:campaign_id' }); }); app.campaignsindexroute = ember.route.extend({ model: function() { app.keyword.find(); homecoming app.campaign.find(); }, rendertemplate: function(controller, model) { this.render({outlet: 'page'}); } }); app.campaignscampaignroute = ember.route.extend({ model: function(params) { alert("model firing"); console.log(params.campaign_id); homecoming app.campaign.find(params.campaign_id); }, rendertemplate: function(controller, model) { this.render({outlet: 'page'}); alert("template firing"); }

});

...and view looks this:

app.campaignscampaignview = em.view.extend({ templatename: 'templates/campaigns/campaign', });

...and main template looks this:

<!-- ================================================== --> <!-- =================== app header =================== --> <!-- ================================================== --> {{ view app.headerview }} <!-- ================================================== --> <!-- ======================= app ====================== --> <!-- ================================================== --> <div id="app" class=""> <!-- ================================================== --> <!-- ==================== sidebar ===================== --> <!-- ================================================== --> <div id="sidebar"> {{ view app.navigationview }} {{ view app.starredcampaignsview }} </div> <!-- ================================================== --> <!-- ====================== stage ===================== --> <!-- ================================================== --> <div id="stage" class=""> <!-- ================================================== --> <!-- ================= stage sidebar ================== --> <!-- ================================================== --> <div id="stage-sidebar" class=""> {{ view app.stagesidebarview }} </div> <!-- ================================================== --> <!-- ====================== page ====================== --> <!-- ================================================== --> <div id="page" class=""> {{ outlet page }} </div> </div> </div>

as can see there 2 simple alerts in campaignscampaign route allow me know beingness activated.

so, /#/campaigns returns list of campaigns, /#/campaigns/new returns creation page , /#/campaigns/:campaign_id should display single campaign , details.

this works within system. when click campaign /#/campaigns view links straight detailed view, proper info loading.

the issue

the problem arises if type in "http://mysite.com/#/campaigns/any_id , don't click link list view. page loads blank , rendertemplate not beingness called (no alert). model loading (getting alert) , params.campaign_id beingness passed (can logged console successfully).

i thinking router issue not sure start. help appreciated.

thanks taking look! can post more info, allow me know need in comments.

the process followed when go straight page different if follow link. don't see links in template i'm not 100% sure happening, in general, if go link

{{#linkto myroute myvar}} link {{/linkto}}

the route not run model function, start myvar model (but still execute setupcontroller function).

so hardlink work, need model function gathers info have been passed in link variable.

routes ember.js

No comments:

Post a Comment