我正在尝试在一条路线中创建一个集合(“内容”)并将它们传递给另一条路线以显示它们。这里有什么问题?
错误:“StartView 中的内容未定义”
这是代码
http://jsfiddle.net/insnet/cmBgz/21/
App = Ember.Application.create({LOG_TRANSITIONS: true});
App.ApplicationController = Ember.Controller.extend();
App.ApplicationView = Ember.View.extend({
templateName: 'application'
});
/* Routing */
App.Router.map(function() {
this.route("start", {path: '/'});
this.route("photos");
});
/* Start */
App.StartController = Ember.ArrayController.extend({
createModels: function() {
this.set('content', Ember.A());
this.addObject(Ember.Object.create({id: 1, title: 'Hello'}));
this.addObject(Ember.Object.create({id: 2, title: 'Digital'}));
this.addObject(Ember.Object.create({id: 3, title: 'World'}));
this.transitionToRoute('photos');
}
});
/* Photos */
App.PhotosView = Ember.CollectionView.extend({
contentBinding : 'App.StartController.content',
didInsertElement : function() {
console.info("content in StartView", this.get('content'));
}
});
<script type="text/x-handlebars" data-template-name="application">
<div class="contrainer">
<div class="hero-unit">
<h1>My App</h1>
{{outlet}}
</div>
</div>
</script>
<script type="text/x-handlebars" data-template-name="start">
<h2>View:Start</h2>
<button {{action "createModels"}} class="btn btn-primary">Create models and goto '/photos'</button>
</script>
<script type="text/x-handlebars" data-template-name="photos">
<h2>View:Photos</h2>
{{#each controller}}
<p>{{title}}</p>
{{/each}}
</script>