! Correction
The binding wasn’t it. As you add up to your schema, you gradually create inconsistencies with missing values (in my case Relations). My .create() call was hitting Parse/Mongo in such a way that the model bindings called for a restart of the main view. Shorthand solution: wipe your data once in a while 🙂
…
My main view has _.bindAll(this, 'addOne', 'addAll', 'render', 'logOut', '...');
In another view I’m setting a Parse.Relation using these 2 chained methods:
1 // If you hit return in the add friend input field, create new Email model
2 // and friend it
3 addFriendOnEnter: function(e) {
4 var self = this;
5 console.log("About to create email "+self.emailInput.val());
6 self.emails.create(
7 {
8 email: self.emailInput.val(),
9 ACL: new Parse.ACL(Parse.User.current())
10 },
11 {
12 success: function (email) {
13 console.log("Email added "+email.get("email"));
14 self.addFriend(email);
15 }
16 },
17 {
18 silent:true
19 }
20 );
21 console.log("Created email");
22 },
23
24 addFriend: function(email) {
25 console.log("Add friend relation to topic "+email.get("email"));
26 this.friendsRel.add(email);
27 console.log("Save topic");
28 this.options.topic.save({silent:true});
29 console.log("Render friend");
30 this.renderOneFriend(email);
31 console.log("Clear input val");
32 this.emailInput.val('');
33 },
The last log I see is line 21, it seems like addFriend isn’t called, and basically the app refreshes itself ie I’m thrown back to the main view which re-renders itself.
One direction I’m suspecting is that the main view is bound to any model changes including a .create() call.
How to unbind that specific call?
Thanks,
Gon
I would add an an error handler to your create call, so you know if maybe that’s getting called instead of success.
Have you tried stepping through the code in Chrome’s JavaScript debugger? Then you’ll know for sure which function is getting called.
silent:true should be in the same options object as success.
You could try creating the object with “var email = new Email(…)” or whatever, and then save it and call self.emails.add(email) in the success handler for the save.