路线:
App.Router.map(function()
{
this.resource("login", { path: "/login"});
this.resource("contacts", { path: "/contacts"}, function ()
{
this.resource("contact", { path: ":contact_id"}, function()
{
this.route("new");
this.route("edit");
});
});
});
App.ContactsIndexRoute = App.AuthenticatedRoute.extend(
{
model: function()
{
return App.Contact.find();
}
});
App.ContactIndexRoute = App.AuthenticatedRoute.extend(
{
model: function()
{
return this.modelFor("contact");
},
setupController: function(controller, model)
{
controller.set("content", model);
}
});
控制器:
App.ContactsIndexController = Ember.ArrayController.extend(
{
setProperties: ['full_name']
});
App.ContactEditControllerr = Ember.ObjectController.extend(
{
});
App.ContactIndexController = Ember.ObjectController.extend(
{
});
当我转到 #/contacts 时,我会从服务器获得完整的联系人列表。如果我转到#/contacts/1,我将获得所有数据,但如果我刷新该页面,数据就消失了,我只剩下裸露的 HTML。问题是如何在嵌套资源中保留模型,以便在页面刷新后它就在那里?