Created
May 23, 2011 17:51
-
-
Save doxavore/987147 to your computer and use it in GitHub Desktop.
This file contains 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
_getObjectAttr: function () { | |
var object = {}, | |
formValues = this.get("value"); | |
for (name in formValues) { | |
if (formValues.hasOwnProperty(name)) { | |
var nameParts = name.replace(/\]/g, '').split('['), | |
building = object; | |
dojo.forEach(nameParts, function (part, idx) { | |
if (idx === nameParts.length - 1) { | |
// This is a value, and the rest should already be built up | |
building[part] = formValues[name]; | |
} | |
else { | |
// Nested object, make sure it exists but don't overwrite it | |
object[part] = object[part] || {}; | |
building = object[part]; | |
} | |
}); | |
} | |
} | |
return object; | |
}, | |
_setObjectAttr: function (/*Object*/ obj) { | |
var formValues = {}; | |
(function (sourceObj, values, prefix) { | |
var formValueName, property, sourceObjValue; | |
for (property in sourceObj) { | |
if (sourceObj.hasOwnProperty(property)) { | |
sourceObjValue = sourceObj[property]; | |
// First value should just be 'prefix', subsequent nested | |
// values should be 'existing[prefix]' | |
formValueName = (prefix) ? (prefix + "[" + property + "]") : property; | |
if (sourceObjValue && dojo.isObject(sourceObjValue)) { | |
arguments.callee(sourceObjValue, values, formValueName); | |
} | |
else { | |
values[formValueName] = sourceObjValue; | |
} | |
} | |
} | |
})(obj, formValues, ""); | |
this.set("value", formValues); | |
return formValues; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment