a.js 747 B

12345678910111213141516171819202122232425262728
  1. const AppRouter = new Backbone.Router({
  2. routes: { "appointments/:id": "show", "": "index" },
  3. initialize: function(options){
  4. this.appointmentList = options.appointmentList;
  5. },
  6. index: function(){
  7. var appointmentsView = new AppointmentListView({collection: this.appointmentList});
  8. appointmentsView.render();
  9. $('#app').html(appointmentsView.el);
  10. this.appointmentList.fetch();
  11. },
  12. show: function(id){
  13. var appointment = new Appointment({id: id});
  14. var appointmentView = new AppointmentView({model: appointment});
  15. appointmentView.render();
  16. $('#app').html(appointmentView.el);
  17. appointment.fetch();
  18. },
  19. start: function() {
  20. Backbone.history.start({pushState: true});
  21. },
  22. });
  23. AppRouter.start();