[英]Using tastypie filters with angularjs and restangular
我正在嘗試使用AngularJS + Restangular與使用Deliciouspie在Django中創建的API進行交互。 我已使用此處找到的示例代碼作為起點成功與API進行了交互(如下所示)。
yourApp.config(function(RestangularProvider) {
RestangularProvider.setBaseUrl("/api");
RestangularProvider.setResponseExtractor(function(response, operation, what, url) {
var newResponse;
if (operation === "getList") {
newResponse = response.objects;
newResponse.metadata = response.meta;
} else {
newResponse = response;
}
return newResponse;
});
RestangularProvider.setRequestSuffix('/?');
});
我想在我的API調用中使用Tastypie的過濾機制,但是這些參數是通過查詢字符串而不是URI發送的。 來自Tastypie文檔的示例: http:// localhost:8000 / api / v1 / entry /?user__username = daniel
除了在每個請求之前重新配置Restangular的setRequestSuffix選項外,是否有任何干凈的方法可以使用Restangular在查詢字符串中應用Tastypie樣式的過濾器?
來自https://github.com/mgonto/restangular/issues/301#issuecomment-24273429
// GET to /partners?where={agentID: 1}
Restangular.all('partners').getList({where: '{agentID: 1}'});
// GET to /partners/123?where={agentID: 1}
Restangular.one('partners', 123).get({where: '{agentID: 1}'});
好像getList()在這里起到了作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.