Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
another little javascript helper
var ApplicationHelpers = {
/**
* Note: requires Underscore.js
*
* Enable a (sencha touch) form to have a link between
* model and form (ie. MyModel.some_attribute <=> textfield.some_attribute)
* AND allow for POST / PUT submission in the rails-friendly namespaced format
* (ie. {my_model[some_attribute] : "some value"}).
*
* To get above behavior, treate model and forms in normal fashion and use
* helper when settings the params for ajax submission (note: using ST 2 PR3):
* Ext.Ajax.request({
* url: '/my_model.json',
* method: 'POST',
* params: helpers.namespace_keys('my_model', params), // <= hooray!
* ...
*/
namespace_keys: function(namespace, obj) {
var self = this,
keys = _.keys(obj);
return _.reduce(keys, function(newObj, k) {
newObj[namespace + '[' + k + ']'] = obj[k];
return newObj;
}, {});
}
};
// alias (it's not just a tv show)
var helpers = ApplicationHelpers;
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.