我正在关注基于http://emberjs.com/guides/outlets/的基于路由器的应用程序结构。
我能够跟随并使其发挥作用。但是当页面显示帖子(例如/#/posts/2)时加载内容时出现问题,我怀疑这是因为未加载特定的帖子。
有什么出路?是不是应该开箱即用。
小提琴示例:http: //jsfiddle.net/nachiket/h5Hkm/
App = Ember.Application.create({});
//MODEL
App.Summary = DS.Model.extend({
content: DS.attr('string')
});
App.Post = DS.Model.extend({
title: DS.attr('string'),
summary: DS.hasMany(App.Summary, {embedded: true})
});
App.Post.FIXTURES = [
{id:1, title: 'My first post', summary: [{id:1, content: 'This is summary1'}]},
{id:2, title: 'Another post' , summary: [{id:2, content: 'This is summary2'}]},
{id:3, title: 'Yet another post' , summary: [{id:3, content: 'This is summary3'}]}
];
//STORE
App.store = DS.Store.create({
revision: 4,
adapter: DS.fixtureAdapter
});
//ROUTER
App.Router = Ember.Router.extend({
root: Ember.Route.extend({
index: Ember.Route.extend({
route: '/',
redirectsTo: 'posts'
}),
posts: Ember.Route.extend({
route: '/posts',
showPost: Ember.Route.transitionTo('post'),
connectOutlets: function(router){
router.get('applicationController').
connectOutlet('posts',App.Post.find());
}
}),
post: Ember.Route.extend({
route: '/posts/:post_id',
goBack: Ember.Route.transitionTo('posts'),
connectOutlets: function(router, post) {
router.get('applicationController').connectOutlet('post', post);
}
})
})
});
//CONTROLLERS - VIEWS
App.ApplicationController = Ember.Controller.extend({});
App.ApplicationView = Ember.View.extend({
templateName: 'application'
});
App.PostsController = Ember.ArrayController.extend({
});
App.PostsView = Ember.View.extend({
templateName: 'posts'
});
App.PostController = Ember.ObjectController.extend({
});
App.PostView = Ember.View.extend({
templateName: 'post'
});
App.initialize();
直接输出: http: //fiddle.jshell.net/nachiket/h5Hkm/show/light/
作品: http: //fiddle.jshell.net/nachiket/h5Hkm/show/light/#/posts
不起作用:http ://fiddle.jshell.net/nachiket/h5Hkm/show/light/#/posts/1