Skip to content
Create a gist now

Instantly share code, notes, and snippets.

backbone example - serialize form + update on change
window.MyView = Backbone.View.extend({
initialize: ->
this.template = window.JST["MyView"]
this.model.bind('change', this.render)
render: ->
events: {
update: ->
form = this.$("form").serializeObject()
jQuery.fn.serializeObject = ->
arrayData = @serializeArray()
objectData = {}
$.each arrayData, ->
if @value?
value = @value
value = ''
if objectData[@name]?
unless objectData[@name].push
objectData[@name] = [objectData[@name]]
objectData[@name].push value
objectData[@name] = value
return objectData

I found it helpful to compile templates into JavaScript, so that they don't have to be included in the page


Great, thanks guys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.