2013-02-18 114 views
2

我想创建一个简单的嵌套视图。 “孩子”视图是一个Ember.Select。 “选择”参数需要来自父级,我无法让它工作。如何做到这一点?Ember.js:从父视图传递参数到嵌套子视图

<script type="text/x-handlebars" data-template-name="application"> 
    {{view App.SelectView contentBindingForSelect="App.names"}} 
</script> 

<script type="text/x-handlebars" data-template-name="select-view"> 
    <h1>In SelectView</h1> 
    {{view view.childSelectView contentBinding="view.contentBindingForSelect"}} 
</script> 


window.App = Ember.Application.create(); 

App.names = ["Yehuda", "Tom"]; 

App.ApplicationView = Ember.View.extend({ 
    templateName: 'application', 
}); 

App.SelectView = Ember.View.extend({ 
    templateName: 'select-view', 
    childSelectView: Ember.Select 
}); 

的jsfiddle例如:http://jsfiddle.net/kRwcU/1/

回答

0

我正在使用ember.js,但如果你检查你的选择元素,这是目前空,你会看到灰烬刚开始实际上已经呈现您查看HTML内选择标签。这显然是垃圾HTML,所以无法正确呈现。

我怀疑正确的答案是你不想以这种方式扩展ember.select来实现功能需求。

+0

对此深感抱歉,我没有正确保存的jsfiddle。这一行:App.SelectView = Ember.Select.extend()应该读取App.SelectView = Ember.View.extend()。因此你猜我看到了什么。我的错。 – PJC 2013-02-18 15:13:37

1

我发现了这个问题......我错过了Ember中的这个“约定”部分:“contentBindingForSelect”作为名称不起作用。单词“绑定”需要保留在最后,例如:“contentForSelectBinding”。我纠正了JSFiddle。现在它工作正常。

http://jsfiddle.net/kRwcU/4/

<script type="text/x-handlebars" data-template-name="application"> 
    <h1>Hello from Ember.js</h1> 
    {{view App.SelectView contentForSelectBinding="App.names"}} 
</script> 

<script type="text/x-handlebars" data-template-name="select-view"> 
    <h1>In SelectView</h1> 
    {{view view.childSelectView contentBinding="view.contentForSelect"}} 
</script>