开发者

Backbone.js TypeError thrown on model.save

In my current Backbone app, I have no problems creating or destroying models. The changes propagate to my server without any problems. But whenever I try to do a model.save(attributes), I see a TypeError thrown at this line: https://github.com/documentcloud/backbone/blob/master/backbone.js#L117

The model is updated on the (Rails) server, but something breaks afterward. Here's the stack trace. (Sorry, line numbers refer to concatenated JS files.)

Backbone.Events.trigger() at application.js:11574 
_.extend._onModelEvent() at application.js:12092 
d() at (internal script):1426Backbone.Events.trigger() at 
application.js:11574 
_.extend.change() at application.js:11808 
_.extend.set() at application.js:11680 
_.extend.save() at application.js:11753 
Map.mapMoveGeoPointMode() at app.js:741 
(anonymous function)() at app.js:894 
jQuery.event.handle() at application.js:开发者_StackOverflow中文版2966 
jQuery.event.add.elemData.handle.eventHandle() at application.js:2600 

In previous applications, I've had no little problems on saving models like this. Any suggestions for what to look at?

Note: I don't think I'm repeating this fellow's problem of trying to save a model with no URL.


Given that the model is updated properly on the server, I don't think this has anything to do with the save() function itself, but rather with the change event it's triggering - I think you could test this simply by calling myModel.trigger('change') and seeing if that throws the same error.

My best guess as to why this is happening is that somewhere along the way you're binding something other than a function - e.g. an undefined variable - to the change event. I'd look for an error like this:

myModel.bind('change', this.misspelledMethod, this);

but it's pretty much impossible to debug further without seeing actual code, not just a stack trace.


It looks like you are binding to an event on the model and passing in something that isn't a valid function. Make sure all of your bind statements pass in functions:

var FUNC = function() {};
MyModel.bind('reset' FUNC);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜