Ember.js 라우팅 예제가 작동하도록 노력하고 있습니다. 나는 게시물 예제로 꽤 잘 돌아가는 바이올린을 가지고있다. 경로가 게시물의 ID로 업데이트되고 올바른 항목이 표시됩니다. 유일한 문제는 게시 URL을 사용하여 콜드 페이지를로드하면 작동하지 않습니다 (포스트보기에 아무 것도 표시되지 않음).엠버 경로 비 직렬화가 부하에서 작동하지 않습니다.
아이디어가 있으십니까? 여기
는 바이올린의 : http://jsfiddle.net/bdennyw/GzYtc/5/전체 URL과 함께 바이올린 http://jsfiddle.net/bdennyw/GzYtc/5/show/#/posts/1
감사
편집 :
$(function() {
App.initialize(App.Router.create());
});
window.App = Ember.Application.create();
App.Post = Ember.Object.extend({
title: null,
body: null
});
App.posts = [];
App.posts.pushObject(App.Post.create({id:'0', title: "Test post 1", body: "How awesome is Ember.js"}));
App.posts.pushObject(App.Post.create({id:'1', title: "Test post 2", body: "I love working on awesome projects"}));
App.posts.pushObject(App.Post.create({id:'2', title: "Test post 3", body: "I like cats"}));
App.ApplicationController = Ember.ObjectController.extend();
App.ApplicationView = Ember.View.extend({
templateName: "application_view"
});
App.PostsController = Ember.ArrayController.extend();
App.PostsView = Ember.View.extend({
templateName: 'posts_view'
});
App.PostController = Ember.ObjectController.extend();
App.PostView = Ember.View.extend({
templateName: 'post_view'
});
App.AboutController = Ember.ObjectController.extend();
App.AboutView = Ember.View.extend({
templateName: 'about_view'
});
App.Router = Ember.Router.extend({
root: Ember.Route.extend({
goToPostsIndex: Ember.State.transitionTo('posts.index'),
goToAbout: Ember.State.transitionTo('about'),
goToShowPost: Ember.State.transitionTo('posts.show'),
index: Ember.Route.extend({
route: '/',
redirectsTo: "posts.index"
}),
posts: Ember.Route.extend({
route: '/posts',
index: Ember.Route.extend({
route: '/',
connectOutlets: function (router) {
router.get('applicationController').connectOutlet('posts', App.posts);
}
}),
show: Ember.Route.extend({
route: '/:post_id',
connectOutlets: function (router, post) {
router.get('postsController').connectOutlet('post', post);
},
deserialize: function(router, params) {
var id = params.post_id,
i = 0;
for (i = 0; i < App.posts.length; i += 1) {
if (App.posts[i].id === id) {
return App.posts[i];
}
}
},
serialize: function(router, context) {
var rtnVal = {},
id = context.get('id');
if (context) {
rtnVal = {post_id: id};
}
return rtnVal;
},
}),
}),
about: Ember.Route.extend({
route: '/about',
connectOutlets: function (router) {
router.get('applicationController').connectOutlet('about');
}
})
})
});
내가 connectOutlets : 레벨을 게시물 아래로 이동해야합니다. sly7_7이 아래에서 말했듯이, 인덱스 상태가 건너 뛰었 기 때문에 뷰가 생성되지 않았습니다. – Brian