Is there a better way to update a model with the values in the form before sending it to the database? I would like to do something like this:
mySave: function () {
this.model.save($(this.el).find(':input').serializeArray());
},
The problem is that .serializeArray() returns an array [{key1:"val1"}, {key2:"val2"}], and the backbone.js model.save() is expecting an object {"key1":"val1", "key2":"val2"} as a param.
The back end is asp.net MVC. I’m mentioning this just in case there are better methods to pass this information back to the server.
Currently, I am just iterating through the serialized array and setting each property on the Backbone Model one by one.
I just wrote this: https://github.com/macek/jquery-to-json
See a demo of it working here http://macek.github.com/jquery-to-json