Ho uno strano comportamento con $ http di AngularJS e non capisco davvero come funzioni transformResponse (i documenti sono un po 'chiari su questo).
WebAssets.get = function() {
return $http.get('/api/webassets/list', {
transformResponse: [function (data, headersGetter) {
// not sure what to do here?!
return data;
}].concat($http.defaults.transformResponse) // presume this isn't needed, added for clarity
}).then(function (response) {
return new WebAssets(response.data);
});
};
L'API restituisce un array di oggetti:
[{"webasset_name": "...", "application_id": "...", "etc": "..."}, ... ]
Ma quando transformResponse ha fatto è business male i dati ha trasformato in un oggetto indicizzato:
{"0":{"webasset_name":"...","application_id":"...", "etc": "..."}, "1":....}
voglio mantenere la struttura dati originale (una serie di oggetti).
Si potrebbe desiderare di avere uno sguardo qui: http://stackoverflow.com/questions/17134401/angular-extending-resource-subobject-with-custom-methods – AlwaysALearner
Stanno usando $ risorsa, sto usando $ http –