2013-06-24 18 views
5

WebLayoutに属するモデルWebsiteTemplateがあります。 UIではwebLayoutsのすべてのリストを表示したいが、idがwebLayoutのものと同じものにhtmlクラスを追加できるようにしたい。 webLayoutは、訪問しているルートのモデルであるwebsiteTemplateに属しています。別のコントローラに関連付けられたモデルを表示

これを行う方法に関するアイデアはありますか?私はセットアップにも根本的に間違ったことがあることを知っているので、それについての考えは歓迎です。私は具体的なwebLayoutrenderに別のパラメータを渡したいと思うようですが、これはEmberのようではありません。

# website_template model 
App.WebsiteTemplate = DS.Model.extend 
webLayout: DS.belongsTo("App.WebLayout") 

# website_layout model 
App.WebLayout = DS.Model.extend 
name: DS.attr("string"), 
thumbnail: DS.attr("string") 

# router 
App.Router.map -> 
@resource "website_template", path: "/website_template/:website_template_id" 

# website_template route 
App.WebsiteTemplateRoute = Ember.Route.extend 
setupController: -> 
@controller.set 'webLayouts', App.WebLayout.find() 

# website_template template 
{{webLayout.id}} 
{{render "_webLayouts" webLayouts}} 

# web_layouts template 
<ul> 
{{#each controller}} 
    <li> 
    <a href="#" {{ action "addLayout" this }}> 
    <img alt="Thumbnail" {{ bindAttr src="thumbnail" }}> 
    {{ name }} 
    </a> 
    </li> 
{{/each}} 
</ul> 

は、私は次のがない作業を行います知っているが、ここで私が達成しようとしているアイデアの擬似コードです。

# website_template template 
{{render "_webLayouts" webLayouts webLayout}} 

# web_layouts template 
<ul> 
{{#each webLayouts in controller}} 
    {{#if webLayouts.id is webLayout.id}} 
    <li class="selected"> 
    {{else}} 
    <li> 
    {{/end}} 
    <a href="#" {{ action "addLayout" this }}> 
    <img alt="Thumbnail" {{ bindAttr src="thumbnail" }}> 
    {{ name }} 
    </a> 
    </li> 
{{/each}} 
</ul> 
+0

あなたは 'WebLayout'モデルの定義を表示できますか? – intuitivepixel

+0

@intuitivepixel私は 'WebLayout'モデルで質問を編集しました。現在のところ、関連はありません。 –

+0

'belongsTo'を使って2つのモデルの間に1対1の関係を宣言すると、そこに関連があると思います。 – intuitivepixel

答えて

1

最初の見方では、2つのモデルの間に1対1の関係が正しく設定されていることが分かりません。

例:その後、

Ember.Handlebars.registerHelper('equal', function(value1, value2, options) { 
    if (value1 === value2) { 
    return options.fn(this); 
    } else { 
    return options.inverse(this); 
    } 
}); 

とこのようにそれを使用します:あなたは基本的に次のようになりますカスタムハンドルヘルパーを書くことができますIDの比較用として

# website_template model 
App.WebsiteTemplate = DS.Model.extend 
    webLayout: DS.belongsTo("App.WebLayout") 

# website_layout model 
App.WebLayout = DS.Model.extend 
    name: DS.attr("string"), 
    thumbnail: DS.attr("string"), 
    websiteTemplate: DS.belongsTo("App.WebsiteTemplate") 

{{#equal webLayouts.id webLayout.id}} 
    are equal 
{{else}} 
    not equal 
{{/equal}} 

ここでは、カスタムヘルパーの作業jsbinを参照してください。

希望します。

+0

@JessicaDillonあなたは' webLayout.id '平等なヘルパーに渡す? – intuitivepixel

関連する問題