2015-02-10 15 views
0

我有一個時間軸上的路線posts與2種類型的帖子:從臉譜和從twitter,兩個相同的控制器:post與2種方法:isFacebookisTwitterEmber零件itemController

每種類型的帖子都有一個組件,而'後期索引'則使用這兩種方法來重新調整正確的組件。

默認ArrayController路線post

<ul class="timeline"> 
    {{#each post in model itemController="posts.post"}} 
    <li> {{post-index post=post}} </li> 
    {{/each}} 
</ul> 

指數後

{{#if post.isFacebook}} 
    {{post-facebook post=post}} 
{{/if}} 

{{#if post.isTwitter}} 
    {{post-twitter post=post}} 
{{/if}} 

{{yield}} 

問題是,當我試圖呈現一個帖子在路線post.post與指數後的模板 路線:

export default Ember.Route.extend({ 
    setupController(controller, model) { 
     this._super(controller, model); 
     controller.set('model', model); 
    } 
}); 

模板:

<ul class="timeline"> 
    {{#each post in model}} 
     <li> {{post-index post=post}} </li> 
     {{/each}} 
</ul> 

我的路線posts只適用,因爲它具有itemController="posts.post"post.post沒有。我應該怎麼辦 ?

回答

0

如果我正確理解您的問題,您想知道如何將帖子本身傳遞給的post屬性。

如果是這樣,你可以按照如下修改代碼:

<ul class="timeline"> 
    {{#each post in model}} 
     <li> {{post-index post=this}} </li> 
     {{/each}} 
</ul> 

唯一的變化是改變崗位this。由於您處於each區塊this將通過當前迭代的項目。

+0

正確的,但決定什麼組件渲染(Twitter或Facebook)'後index'需要使用控制器('posts.post')方法(isFacebook/isTwitter這將檢查模型屬性),或這種邏輯應該是移動(在哪裏?)? – 2015-02-11 03:57:57

+0

我不知道我100%理解你的問題。你的模型是否有'isFacebook'和'isTwitter'方法?如果是這樣,將帖子傳遞給'post-index'並利用您在模板中發佈的邏輯應該可行。有沒有像你期望的那樣發揮作用? – 2015-02-11 04:16:48

+0

我的模特有'social_network'屬性。 我的控制器'posts.post'方法'#isFacebook''#isTwitter'返回true,如果這個屬性是'臉譜'或'微博',但是這會在控制器和組件之間創建依賴關係。我需要'post-index'中的一種方式來決定是否使用組件呈現。 – 2015-02-11 05:11:29