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で、私は3つの変数、page、fieldName、directionを解決できる辞書を渡したいと思います。
var n = {};
n.page = $scope.currentPage;
n.fieldName = $scope.fieldName
n.direction = $scope.direction
しかし、これは機能しません。 GET URL文字列を調べると、anglejsはfieldNameとdirectionの識別子を辞書の値に置き換えません。次のURLスキームはGET'edれる:
/API /スケジュール方向= ASC &フィールド名ID = &ページ= 1つの& Q = { "ORDER_BY":[{ "フィールド": "@のフィールド名"、 "方向「:」@方向 "}]}ここで
私は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;
});
誰もが、私はこれを具体的に対処する方法を推奨していますか?