2017-03-24 38 views
1

我在angularjs應用程序中有以下工廠方法。將字典傳遞給ngResource以獲得多個URL參數

var mod = angular.module('scheduleApp.services', ['ngResource', 'ui.bootstrap']); 

mod.factory('SchedulesFactory', function ($resource) { 
    return $resource('http://devhost\\:8080/api/schedule', {}, { 
     query: { method: 'GET', isArray: false}, 
     create: { method: 'POST' }, 
     getPage: { method: 'GET', 
        params: {page: '@page', 
           q: {"order_by": [{"field": "@fieldName", "direction": "@direction"}]}} }, 
     getPageSorted: {method: 'GET'} 

    }); 
}); 

在我的GET處理程序,GETPAGE,我想通過我從中可以解決三個變量,頁面,字段名和方向的字典。

var n = {}; 
n.page = $scope.currentPage; 
n.fieldName = $scope.fieldName 
n.direction = $scope.direction 

但這不起作用。當我檢查我的GET URL字符串時,angularjs不會使用我的字典中的值替換fieldName和direction標識符。以下URL方案GET'ed:

/API /時間表方向= ASC &的fieldName = ID &頁= 1個& Q = { 「ORDER_BY」:[{ 「字段」: 「@ fieldName的」,「方向「:」 @方向「}]}

這是我如何調用getPageSorted程序:

var n = {}; 
n.page = $scope.currentPage; 
n.fieldName = "id" 
n.direction = "asc" 
SchedulesFactory.getPage(n, function(object) { 
    console.log(object); 
    $scope.schedules = object.objects; 
    $scope.totalItems = object.num_results; 
}); 

沒有人有一個建議,我怎麼能專門解決這個問題?

回答

1

我不相信ng-resources支持你正在做的事情。你將需要放置一個函數來代替「q」,並在那裏做你自己的改變。