2012-12-31 69 views
4

我對Ember.js非常陌生,在開發應用程序時,我剛剛瞭解到有關新的路由器API。這是合併,並沒有任何文檔(除此 - https://gist.github.com/3981133Ember.js:將應用程序轉換爲路由器API V2

我不知道如何甚至開始轉換我的應用程序到新的路由器API。 這個「演練」沒有多大幫助。

1)如何將模板連接到指定插座,例如{{outlet main}}? 2)我使用App.router.someController和App.router.get('store')。findAll()和.find()到處都是,應該用什麼替換?

3)html html <script type="text/x-handlebars" data-template-name="templateName">中的handlebars標籤是否有任何更改?

,所有我能想到現在...

+2

我發現這個相當豐富的內容:http://www.youtube.com/watch?v=4Ed_o3_59ME –

+1

我也做了一個介紹ember.js和新的路由器屏幕截圖的任何人可能試圖學習新的api http://toranbillups.com/blog/archive/2013/01/03/Intro-to-ember-js-and-the-new-router-api/ –

回答

5

我只是完成這個升級自己的一個小例子項目

https://github.com/toranb/ember-code-camp

回答幾個您的問題直接

1 )不再有connectOutlets噪聲 - 只需將路由映射到一個ember路由類/對象。這種方法BTW(模板/視圖/控制器/路由的所有比賽)基於非常約定

CodeCamp.Router.map(function(match) { 
    match("/").to("sessions"); 
    match("/session/:session_id").to("session"); //no route needed -ember will apply the context for you 
    match("/speaker/:speaker_id").to("speaker"); //same as above so long as my handlebars template name matches (speaker for this route) 
}); 

CodeCamp.SessionsRoute = Ember.Route.extend({ 
    setupControllers: function(controller) { 
    controller.set('content', CodeCamp.Session.find()); 
    } 
}); 

2)你在路由器店裏像這樣

App.YourObject.find() 

2 b)您可以提交商店從您的控制器中,像這樣

this.get('store').commit() 

3)我的車把東西是與路由相關的幫手除外不變

I remove action helpers defined with <a {{action and used linkTo instead 

    {{#linkTo 'session' session}}View Session Details{{/linkTo}} 
+1

關於1),你如何設置多個控制器在一個路線? (例如,我想在連接到{{outlet navigation}}的NavigationController中設置一些東西。 –

+0

好問題 - 從我所知道的情況來看,約定是每個路由只有1個控制器,但是文檔實際上是真的如果在將來我偶然發現一些文檔,我會更新這個答案: –

+1

在路由中設置多個控制器:從setupControllers()回調設置屬性,然後從renderTemplates回調連接出口。例如,在setupControllers()中,你會做controllerFor('navigation').set('a','b')和renderTemplates()調用render('navigation',{controller:'navigation',outlet:'navigation }) –

相關問題