Created
January 18, 2013 16:42
-
-
Save markupboy/4565933 to your computer and use it in GitHub Desktop.
backbone form helpers
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
_.extend Backbone.View.prototype, | |
parse: (objName) -> | |
_recurse_form = (object, objName) => | |
_.each object, (v,k) -> | |
if v instanceof Object | |
object[k] = _recurse_form v, "#{objName}[#{k}_attributes]" | |
else | |
object[k] = @$("[name=#{objName}[#{k}]]").val() | |
return object | |
@model.attributes = _recurse_form @model.attributes, objName | |
populate: (objName) -> | |
_recurse_obj = (object, objName) => | |
_.each object, (v,k) -> | |
if v instanceof Object | |
_recurse_obj v, objName + "#{objName}[#{k}_attributes]" | |
else if _.isString(v) | |
@$("[name=#{objName}[#{k}]]").val(v) | |
_recurse_obj @model.attributes, objName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment