ember.js - EmberJS: Load a teaser of a model for a list, full model for detail view -
anyone figure out how partially load model 1 view, load entire model another?
for example:
/* projects, want id , name returned server. each project monster, don't want data each project. */ app.projectsroute = ember.route.extend({ model: function () { return app.project.find(); } }); /* project detail, we'd want entire model returned server. embedded records , all. */ app.projectroute = ember.route.extend({ });
the closest thing find this: https://stackoverflow.com/a/14183507/1125563
in can this:
app.projectroute = ember.route.extend({ setupcontroller: function(controller, model) { if (model.get('isteaser')){ model.reload(); } } });
in workaround, have computed property isteaser checks few things determine if i've partially loaded it.
other being little messy, deal breaker here it's transitioning route partially loaded model , after it's loaded, stuff kind of in-elegantly snap in. not fan..
am missing obvious?
here's approach eliminates initial rendering delay. meant 'inelegant snap in'?
// load light version of subjects on page load app.applicationcontroller = em.controller.extend({ init: function() { return app.subject.find(); } }); // fetch our loaded subjects app.subjectsroute = ember.route.extend({ model: function() { return app.subject.all(); } }); app.subjectroute = ember.route.extend({ // if we're loading page directly route, normal find model: function(params) { return app.subject.find(params.subject_id); }, setupcontroller: function(controller, model) { // show details have subject (e.g. title) controller.set("model", model); // load full details model , display them arrive if (em.isempty(model.get("text"))) { app.subject.find(model.get("id")).then(function(model) { return controller.set("model", model); }); } } });
Comments
Post a Comment