こんにちは、Wordpress で作成されたバックエンドと REST API を使用してアプリを開発しています。
しかし、私は応答を解析できず、その理由がわかりません。まず、それは一種の json 応答だったと思います。それが、setResponseInterceptor メソッドを実装した理由です。
ここでの問題は、setResponseInterceptor かどうかわからないことです。デバッグ コードを追加すると、weiner にログが表示されません。
私はいくつかのグローバル構成を持つ次のモデルを持っています:
// The contents of individual model .js files will be concatenated into dist/models.js
(function() {
// Protects views where angular is not loaded from errors
if ( typeof angular == 'undefined' ) {
return;
};
var module = angular.module('Provedores_floresModel', ['restangular']);
module.factory('Provedores_floresRestangular', function(Restangular) {
return Restangular.withConfig(function(RestangularConfigurer) {
RestangularConfigurer.setBaseUrl('https://public-api.wordpress.com/rest/v1/sites/www.bride2be.com.mx/');
RestangularConfigurer.setResponseInterceptor(function(response, operation, what, url){
var newResponse;
if (operation === "getList") {
newResponse = response.posts;
}
return newResponse;
});
});
});
})();
そしてこのコントローラー:
var provedores_floresApp = angular.module('provedores_floresApp', ['Provedores_floresModel', 'hmTouchevents']);
// Index: http://localhost/views/provedores_flores/index.html
provedores_floresApp.controller('IndexCtrl', function ($scope, Provedores_floresRestangular) {
// Helper function for opening new webviews
$scope.open = function(id) {
webView = new steroids.views.WebView("/views/provedores_flores/show.html?id="+id);
steroids.layers.push(webView);
};
// Fetch all objects from the local JSON (see app/models/provedores_flores.js)
$scope.provedores_floress = Provedores_floresRestangular.all('posts?type=ceremonia').getList().then(function() {
alert("All ok");
}, function(response) {
alert(JSON.stringify(response));
});
// -- Native navigation
steroids.view.navigationBar.show("Flores");
});
then コードブロックで、次の応答を得ました。
{
"data": "",
"status": 0,
"config": {
"method": "GET",
"headers": {},
"url": "https://public-api.wordpress.com/rest/v1/sites/www.bride2be.com.mx/posts?type=ceremonia"
}
}