Angularjs 为多个URL参数向ngResource传递字典

Angularjs 为多个URL参数向ngResource传递字典,angularjs,Angularjs,我在angularjs应用程序中使用了以下工厂方法 var mod = angular.module('scheduleApp.services', ['ngResource', 'ui.bootstrap']); mod.factory('SchedulesFactory', function ($resource) { return $resource('http://devhost\\:8080/api/schedule', {}, { query: { meth

我在angularjs应用程序中使用了以下工厂方法

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中,我想传递一个字典,从中可以解析三个变量:page、fieldName和direction

var n = {};
n.page = $scope.currentPage;
n.fieldName = $scope.fieldName
n.direction = $scope.direction
但这不起作用。当我检查GET URL字符串时,angularjs不会用字典中的值替换字段名和方向标识符。已获取以下URL方案:

/api/schedule?direction=asc&fieldName=id&page=1&q={“order_by”:[{“field”:“@fieldName”,“direction”:“@direction”}]}

下面是调用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;
});

有人建议我如何具体解决这个问题吗?

我不相信ng resource支持您正在尝试做的事情。您需要将一个函数替换为“q”,并在那里进行您自己的更改