WebLayout
に属するモデルWebsiteTemplate
があります。 UIではwebLayouts
のすべてのリストを表示したいが、idがwebLayout
のものと同じものにhtmlクラスを追加できるようにしたい。 webLayout
は、訪問しているルートのモデルであるwebsiteTemplate
に属しています。別のコントローラに関連付けられたモデルを表示
これを行う方法に関するアイデアはありますか?私はセットアップにも根本的に間違ったことがあることを知っているので、それについての考えは歓迎です。私は具体的なwebLayout
とrender
に別のパラメータを渡したいと思うようですが、これは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>
あなたは 'WebLayout'モデルの定義を表示できますか? – intuitivepixel
@intuitivepixel私は 'WebLayout'モデルで質問を編集しました。現在のところ、関連はありません。 –
'belongsTo'を使って2つのモデルの間に1対1の関係を宣言すると、そこに関連があると思います。 – intuitivepixel