1
votes

I am scratching my head over an issue with backbone...

I have a backbone view, with an event which calls a function that saves the current model.

Its a simple form, in the view I do some validation before syncing the model.

this.model.save({
    completed : completed,
    company : company,
    revenue : revenue,
    term : term,
    comments : comments,
    probability : probability
  },
  {
    success: function (model, response) {
    console.log('success', model, response);
    Evision.trackRouter.navigate("tracker/", {trigger: true});
    },
    error: function (model, response) {
      console.log('error', model, response);
    }
  } 
;

After success is fired it returns me back to my collection of models, where I can select another model to edit, its at this point when i attempt to save that i receive in my console and Chrome crashes.

If i expand this error it is indicating a problem with the function running the above, and my model is logged out in the console but when i try to expand it its empty?

Its worth saying that neither success or error is being fired ont he 2nd route round.

Thanks

Edit #1

Here is the error i receive before the crash

    <error>
    w.extend
    w.clone
    e.extend.toJSON
    _.extend.save
    _.extend.update
    LocalStorage.sync
    Backbone.sync
    e.extend.sync
    e.extend.save
    Evision.Views.TrackerDetail.Backbone.View.extend.saveTracker
    (anonymous function)
    j

Edit #2 Here is my model

Evision.Models.Track = Backbone.Model.extend({

  defaults: function() {
    return {
      id : Evision.trackerList.nextOrder(),
      completed : false,
      created : Utils.datestamp(),
      company : "",
      revenue : "",
      term : "",
      comments : "",
      probability : "",
      success : null
    }
  }


});
2
What is the exact error in the console, or do you mean Chrome actually crashes so you can't access the console anymore?jevakallio
@fencliff i have updated my post with the error i receive before the browser crashesMart
Interesting. Looking at the stack trace, the error occurs inside underscore's extend method. Can't think of any reason why that would happen. Can you post your model code as well?jevakallio
@fencliff the odd thing is this does work and save fine, its only once i try to save for the 2nd time that I have the problemMart
Yep, this is actually very weird. Are you using underscore or lo-dash, and which version? Can you try to console.log(this.model.toJSON()) before save and see if that outputs OK, or does it crash also? What would be great if you could try to replicate this somewhere online. Here's a empty tinker.io with Backbone etc. already loaded: tinker.io/d2fed/3 . Are you able to get this error there?jevakallio

2 Answers

1
votes

I know exactly the problem. I had this issue not so long back. First thing I looked at was the stack trace and just like in the comments above I was getting an extend problem with underscore. What you need to do is update backbone.js, underscore.js and backbone-localstorage.js(if you have it) to the most recent versions. The problem lies with versioning!

0
votes

Turns out the issue was related to a modified version of Jerome's Backbone.localStorage, which would allow for both remote and local storage within the app. I replaced with the latest localStorage adapter and everything is working fine. Unfortunately I cant find the original source to notify.