我正在尝试从容器视图、子视图访问父视图数据,但没有成功。
这是一个提琴手。
这样做的正确方法是什么?
使用:ember-1.0.0-rc.1.js
Javascript代码:
App = Ember.Application.create({
rootElement: '#app',
name: 'My app',
ready: function(){
console.log('ready');
},
});
App.mod = Ember.Object.extend({
value: null,
computed: function(value) {
return 'computed';
}.property()
});
App.MyController = Ember.ArrayController.create({
content: [],
init: function(){
// create an instance of the model
var item = App.mod.create({
value: 'somevalue'
});
this.pushObject(item);
}
});
App.SecondView = Ember.View.extend({
tagName: 'span',
classNames: ['second'],
template: Ember.Handlebars.compile("second view with values: '{{value}}' & '{{computed}}'"),
});
App.FirstView = Ember.View.extend({
tagName: 'span',
classNames: ['first'],
template: Ember.Handlebars.compile("first view"),
});
App.ViewsContainer = Ember.ContainerView.create({
tagName: 'span',
classNames: ['Container'],
childViews: ['first_v', 'second_v'],
first_v: App.FirstView,
second_v: App.SecondView
});
和模板:
<div id="app">
<script type="text/x-handlebars">
Test <b>{{App.name}}</b><br><br>
{{#each App.MyController.content}}
this should be printed: "{{value}}" & "{{computed}}"<br><br>
{{view App.ViewsContainer}}
{{/each}}
</script>
</div>