動的なchildViewsを備えたContainerViewを使用してこれを解決することになりました。方法については、 Ember.jsの動的な子ビューを参照してください。
関連するコードは(coffeescript)です:
App.SelectorType = Ember.Object.extend
name: null
type: null
typeView: null
options: null
App.SelectorTypes = [
App.SelectorType.create(
name: 'foo'
type: 'bar'
) #, more etc
]
App.SelectorTypes.forEach (t) ->
t.set 'typeView', Ember.View.create
templateName: "selectors/_#{t.get('viewType')}_view"
name: t.get('name')
App.SelectorDetailView = Ember.ContainerView.extend
didInsertElement: ->
@updateForm()
updateForm: (->
type = @get('type')
typeObject = App.SelectorTypes.findProperty('type', type)
return if Ember.isNone(type)
view = typeObject.get('typeView')
@get('childViews').forEach (v) -> v.remove()
@get('childViews').clear()
@get('childViews').pushObject(view)
).observes('type')
そしてテンプレート:
Selector Type:
{{view Ember.Select
viewName=select
contentBinding="App.SelectorTypes"
optionValuePath="content.type"
optionLabelPath="content.name"
prompt="Pick a Selector"
valueBinding="selector.type"
}}
<dl>
<dt><label>Details</label></dt>
<dd>
{{view App.SelectorDetailView typeBinding="selector.type"}}
</dd>
</dl>
しかし、難しすぎるようですが、より良い解決策を見たいと思っています!