Created
August 2, 2013 14:09
-
-
Save knownasilya/6140169 to your computer and use it in GitHub Desktop.
Ember Data modify props.
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
ajax: function (url, type, hash) { | |
var adapter = this; | |
return new Ember.RSVP.Promise(function (resolve, reject) { | |
hash = hash || {}; | |
hash.url = url; | |
hash.type = type; | |
hash.dataType = "jsonp"; | |
hash.context = adapter; | |
if (hash.data && type !== "GET") { | |
hash.contentType = "application/json; charset=utf-8"; | |
hash.data = JSON.stringify(hash.data); | |
} | |
hash.success = function (json) { | |
var transformedJSON = adapter.transformJSON(json, hash.root); | |
Ember.run(null, resolve, transformedJSON); | |
}; | |
hash.error = function (jqXHR, textStatus, errorThrown) { | |
Ember.run(null, reject, errorThrown); | |
}; | |
jQuery.ajax(hash); | |
}); | |
}, | |
transformJSON: function (json, root) { | |
var feature, | |
index = 0, | |
pluralizedRoot = this.pluralize(root), | |
transformedJSON = {}; | |
transformedJSON[pluralizedRoot] = []; | |
for(;index < json.features.length; index++) { | |
feature = json.features[index]; | |
if(feature.geometry) { | |
feature.attributes.geometry = feature.geometry; | |
} | |
transformedJSON[pluralizedRoot].push(feature.attributes); | |
} | |
return transformedJSON; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment