Advertisement
Guest User

Untitled

a guest
Mar 12th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. window.Site = Backbone.RelationalModel.extend({
  2. idAttribute: "_id",
  3. // These are the relations to the user model.
  4. relations: [{
  5. type: Backbone.HasMany,
  6. key: 'users',
  7. relatedModel: 'window.User'
  8. }],
  9.  
  10. });
  11.  
  12. //Site User model
  13. // -------------
  14.  
  15. window.User = Backbone.RelationalModel.extend({
  16. });
  17.  
  18. {
  19. _id: foo,
  20. users: [
  21. username: bar,
  22. password: fizz
  23. ]}
  24.  
  25. initialize: function() {
  26.  
  27. //basic bindings
  28. this.model.bind('change', this.setSave, this);
  29. this.model.bind('destroy', this.remove, this);
  30.  
  31. // bindings to sub-models
  32. this.model.bind('add:users', this.setDetailsView, this);
  33. this.model.bind('remove:users', this.setSave, this);
  34. this.model.bind('change:users', this.setSave, this);
  35.  
  36. initialize: function() {
  37. this.model.bind('change', this.render, this);
  38. this.model.bind('destroy', this.remove, this);
  39.  
  40. this.model.get('users').each(function(user){
  41. user.bind(change,this.render,this);
  42. },this);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement