ember.js - Right way to architect two paths for adding users -
right have following app - http://jsbin.com/okoxim/7/edit
it allows person browse users name or class. if browsing users, , click new user, new form no default values, , upon save directed user details.
when browsing class want give option add new user , new form should default current class on when new user option selected , upon save, should route class saved.
what right way setup routes facilitate scenario , how should reuse existing new controller this?
you can use custom event
manage inside route. view/controller bubble event route, takes care of adding student given data.
app.applicationroute = em.route.extend({ events: { createstudent: function(student, gradeid) { var grade = app.grade.find(gradeid); var newstudent = app.student.create({ name: student.name, address: student.address, grade: grade }); newstudent.save(); // other application related stuff } } });
and controller use send
dispatch event data route.
save: function() { var gradeid = this.get('newgrade'); var student = { name: this.get('newname'), address: this.get('newaddress') }; this.send('createstudent', student, gradeid); // other view related stuff }
the createstudent
event can reused different controllers/views.
Comments
Post a Comment