【发布时间】:2014-01-26 16:41:43
【问题描述】:
Restangular 缺乏文档,这让我很生气。 我正在尝试使用 REST 端点。我使用 Django-Tastypie 作为后端提供程序。
var baseQuestions = Restangular.all('questions');
baseQuestions.one($routeParams.questionId).get().then(function(question) {
console.log(question);
});
在我的 AngularJS 应用程序配置函数中,我确保我以正确的方式设置了 Restangular。
RestangularProvider.setBaseUrl('/api/v1');
RestangularProvider.setRequestSuffix('?format=json');
RestangularProvider.setResponseExtractor(function(response, operation, what, url) {
var newResponse;
if (operation === 'getList') {
newResponse = response.objects;
newResponse.metadata = response.meta;
} else {
newResponse = response.data;
}
return newResponse;
});
但打印的控制台值显示问题未定义,显然我不希望这样,我需要实际数据。
REST 端点在浏览器中运行良好。
谁能告诉我我做错了什么?
【问题讨论】:
-
你能
console.log(response, operation)吗?
标签: javascript angularjs rest tastypie restangular