Guest User

Untitled

a guest
Oct 15th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. // Router is responsible for driving the application. Usually
  2. // this means populating the necessary data into models and
  3. // collections, and then passing those to be displayed by
  4. // appropriate views.
  5. var Router = Backbone.Router.extend({
  6. routes: {
  7. '': 'index' // At first we display the index route
  8. },
  9.  
  10. index: function() {
  11. // Initialize a list of people
  12. // In this case we provide an array, but normally you'd
  13. // instantiate an empty list and call people.fetch()
  14. // to get the data from your backend
  15. var people = new models.People([
  16. {
  17. firstname: 'Arthur',
  18. lastname: 'Dent'
  19. },
  20. {
  21. firstname: 'Ford',
  22. lastname: 'Prefect'
  23. }
  24. ]);
  25.  
  26. // Pass the collection of people to the view
  27. var view = new views.People({
  28. collection: people
  29. });
  30.  
  31. // And render it
  32. view.render();
  33.  
  34. // Example of adding a new person afterwards
  35. // This will fire the 'add' event in the collection
  36. // which causes the view to re-render
  37. people.add([
  38. {
  39. firstname: 'Zaphod',
  40. lastname: 'Beeblebrox'
  41. }
  42. ]);
  43. }
  44. });
  45.  
  46. jQuery(document).ready(function() {
  47. // When the document is ready we instantiate the router
  48. var router = new Router();
  49.  
  50. // And tell Backbone to start routing
  51. Backbone.history.start();
  52. });
Add Comment
Please, Sign In to add comment