Created
February 9, 2013 00:00
-
-
Save adatta02/4743008 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Language = Backbone.Model.extend({ | |
defaults: function() { | |
return { | |
languageName: "", | |
}; | |
}, | |
initialize: function() { | |
}, | |
url: "echoBackbone.php", | |
sync: function(method, model, options){ | |
var methodMap = { | |
'create': 'POST', | |
'update': 'PUT', | |
'delete': 'DELETE', | |
'read': 'GET' | |
}; | |
var type = methodMap[method]; | |
// Default options, unless specified. | |
options || (options = {}); | |
// Default JSON-request options. | |
var params = {type: type, dataType: 'json'}; | |
// Ensure that we have a URL. | |
if (!options.url) { | |
params.url = this.url || urlError(); | |
} | |
// Don't process data on a non-GET request. | |
if (params.type !== 'GET' && !Backbone.emulateJSON) { | |
params.processData = false; | |
} | |
// NEW - the juicy bits to combine all the models in this collection | |
var collection = []; | |
model.collection.each( function(e, i, l){ | |
collection.push( e.toJSON() ); | |
}); | |
params.data = JSON.stringify(collection); | |
// Make the request, allowing the user to override any Ajax options. | |
return $.ajax(_.extend(params, options)); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment