AngularJSの$ httpで奇妙な動作が起こり、transformResponseがどのように機能するか理解できていません(この文書では少し明るいです)。
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);
});
};
APIは、オブジェクトの配列を返します。
[{"webasset_name": "...", "application_id": "...", "etc": "..."}, ... ]
をしかしtransformResponseが、それは邪悪なビジネスだ行っているときに、データをインデックス付きオブジェクトに変換している:私は維持したい
{"0":{"webasset_name":"...","application_id":"...", "etc": "..."}, "1":....}
元のデータ構造(オブジェクトの配列)
を使用してみてください:http://stackoverflow.com/questions/17134401/angular-extending-resource-subobject-with-custom-methods – AlwaysALearner
彼らは$ resourceを使用しています、私は$ httpを使用しています –