Updating parent view in backbone.js -
Target: Use backbone to create users' table, be able to edit users inline and save , Re-provide the row with updated data.
- I am creating a container table for users with a main user view.
- Then I'm looping through a user archive, and using a UserView to create a table row per user.
- Clicking on any line requires changing the row with an edit form (more fields are connected to the user displayed in the table.) < Li> Click Save to modify the editing form with updated table row
Everything works except the render of the table row (if I reload the page , Then update the sub The owner data is displayed correctly, so I know that it has to be saved.) What I'm trying to do (I think) View and view parental views (user view) Receives user views dozens of searches and after different attempts, I am here to help say what I am doing wrong. thank you in advanced.
// See main user
var UsersView = Backbone.View.extend ({el: '#content', template: _. Template (usersTemplate), start: function () {var key = this; in the list (user, 'change', this.updateOne); Users.fetch (); that.render ();}, render: Function Add a single user to the addOne: function (user) {var userView = new UserView ({Model: user}); User View Render () {this. $ El.html (this.template);} .EL;}, // Add all items to the user collection addAll: function () {Users.each (thi) S.addOne, this);}});
// Personal user view
var UserView = Backbone.View.extend ({el: '#usersTableBody' Tag name: 'tr', attributes: function () {Returns '' Data-User '': this.model.get ('display_name')}}, Template: _Template (User Template), Event: {'click.editUser' : 'EditUser'}, start: function () {}, render: function () {var html = this.template (this.model.attributes); this. $ El.html (html);}, // switch edit User Row Edit User in Mode: Function (E) {E.Page Default (); var UserEditView = New UserAditEdit Electricity ({Model: this.model}); UserEditViv.Redder ();}});
// user editable view
var userAdit Viv = backbone.View Extension ({L: $ ('# content (), template: _.template (userEditTemplate), Event: {' click .saveUser ':' saveUser '}, get started: function (option) {}, render: function ( ) {Element = '[data-user =' + this.model.get ('display_name') + '"]' this. $ El.find (element) .hide () .after (this.template (this.model .attributes);}, saveUser: function () (var display_name = this. $ ('#display_name') .val () .trim (); var email_address = this. $ ('#email_address') .val () .tim (); var key_email_address = this $ ('#key_email_address') .val () .trim (); var password = this. $ ('#password') .val () .trim (); var partner_name = this . $ ('#partner_name'). Val () .trim (); var hash = this. $ ('#hash') .val () .trim (); var salt = this. $ ('#salt') .val () .trim (); Users.create ({display_name: display_name, key_email_addr Ess: key_email_address, email_address: email-address, password: password, partner_name: pa rtner_name, hash: hash, salt: salt});}});
// user Model
var UserModel = Backbone.Model.extend ({idAttribute: 'key_email_address'});
// user archive
var UsersCollection = Backbone.Collection.extend ({Model: user, url: 'user ', Start: function (model, option) {}, pars: function (data) {this.result = data.result; return data.users;}});
There is no
change on any changes On collection items.
So your following line should not really do anything:
this.listenTo (user, 'change', this.updateOne);
You must include the following in your
UserView
initialize method:
this.listenTo (This.model, 'change', This.render);
So whenever the model changes (on editing), the existing user row is presented again
Comments
Post a Comment