问题
I have a strange problem with ember-data, on one entry point it loads the data from the server (I enabled logging on the server to see what's happening), but on a different entry point and then change route to the same state as the first option, ember-data doesn't access the server at all.
I simply can't understand why this is happening.
in my app, if I point the browser to /posts, data is loaded from the server and everything is ok. but if I point to /settings, and then follow a link to change routes to posts.index, ember-data doesn't access the server.
also, if my entry point is /posts/new and I try to create a new post I get an error:
http://localhost:3000/api/unknown%20mixin)s 404 (Not Found)
what can be the problem ?
EDIT: If I load data by invoking findAll()
in the controller's init function, the data is loaded when the controller is first instantiated and everything is fine.. but I still don't understand this weird behavior. is it a bug ?
EDIT2: I created a github project to show this issue - https://github.com/bsphere/ember-data-test
App.Router = Ember.Router.extend({
enableLogging: true,
root: Ember.Route.extend({
showposts: Ember.Route.transitionTo('posts.index'),
showSettings: Ember.Route.transitionTo('settings.index'),
index: Ember.Route.extend({
route: '/',
connectOutlets: function(router) {
router.transitionTo('posts.index');
}
}),
settings: Ember.Route.extend({
route: '/settings',
connectOutlets: function(router) {
router.get('applicationController').connectOutlet('navigation', 'navigation');
},
index: Ember.Route.extend({
route: '/',
connectOutlets: function(router) {
router.get('applicationController').connectOutlet('content', 'settings');
router.set('navigationController.selected', 'settings');
}
})
}),
posts: Ember.Route.extend({
newpost: Ember.Route.transitionTo('root.posts.new'),
editpost: Ember.Route.transitionTo('root.posts.edit'),
route: '/posts',
connectOutlets: function(router) {
router.get('applicationController').connectOutlet('navigation', 'navigation');
},
index: Ember.Route.extend({
route: '/',
connectOutlets: function(router) {
router.set('navigationController.selected', 'posts');
router.get('applicationController').connectOutlet('content', 'posts',
App.store.findAll(App.Post));
}
}),
new: Ember.Route.extend({
route: '/new',
connectOutlets: function(router) {
router.set('navigationController.selected', '');
router.get('applicationController').connectOutlet('content', 'post',
App.store.createRecord(App.Post));
router.set('postController.isEditing', false);
},
cancel: function(router) {
router.transitionTo('index');
},
didCreate: function(router) {
router.transitionTo('index');
}
}),
edit: Ember.Route.extend({
route: '/:id/edit',
connectOutlets: function(router, post) {
router.set('navigationController.selected', '');
router.get('applicationController').connectOutlet('content', 'post',
App.store.find(App.Post, post.get('id')));
router.set('postController.isEditing', true);
},
deserialize: function(router, context) {
return App.store.find(App.Post, context.id)
},
serialize: function(router, post) {
return {
id: post.get('id')
}
},
cancel: function(router) {
router.transitionTo('index');
},
didUpdate: function(router, post) {
router.transitionTo('index');
}
})
})
})
});
来源:https://stackoverflow.com/questions/14033252/ember-data-working-as-expected-only-if-app-entry-point-access-data