使用 $resource 在同一查询中多次将相同的参数传递给 Rest 服务
Passing same parameter, multiple times in same query to Rest service using $resource
我正在使用我的 AngularJS 应用程序中的这个 Rest Web 服务,我正在使用 $resource 传递参数和获取我的数据。
我有一个特定的服务可以在我的 Postman 会话中像这样多次使用相同的参数:
/myService/Accounts?acctId[]=7029&acctId[]=3324
我试图将生成的字符串传递到我的 $resource 查询方法占位符,但它最终转义了我的所有括号并且无法正常工作。
我也尝试过不使用占位符并两次传递相同的参数,它没有失败,但它采用了最后一个值,因此也不起作用。
$scope.resultsColl = rfpService.searchAccountName.query({
acctName: $scope.accountName,
acctRole: acctRoleParams,
acctRole: acctRoleParams2
});
希望有人遇到过同样的问题?有什么想法吗?
根据我对其他 post 所做的研究,您似乎无法使用 $resource 动态生成。我的工作解决方案是切换到 $http,这样我就可以动态生成多个 acctRole[] 参数:
var acctRoleParams = '';
if(corporate === true)
{
acctRoleParams = '&acctRole[]=C';
};
if(smallBiz === true)
{
acctRoleParams += '&acctRole[]=B';
};
$http.get("https://myRestServiceUrl/services/customer/accounts?acct=" + $scope.account + acctRoleParams)
.success(function (data, status, headers, config) {
$scope.gridOptions.data = data.data.detailsByAcct;
})
.error(function (data, status, headers, config) {
showToast("An error occurred during the request");
})
.finally(function () {
$scope.isGridLoading = false;
});
我想 post 以防其他人一直在努力做同样的事情。
我正在使用我的 AngularJS 应用程序中的这个 Rest Web 服务,我正在使用 $resource 传递参数和获取我的数据。
我有一个特定的服务可以在我的 Postman 会话中像这样多次使用相同的参数:
/myService/Accounts?acctId[]=7029&acctId[]=3324
我试图将生成的字符串传递到我的 $resource 查询方法占位符,但它最终转义了我的所有括号并且无法正常工作。
我也尝试过不使用占位符并两次传递相同的参数,它没有失败,但它采用了最后一个值,因此也不起作用。
$scope.resultsColl = rfpService.searchAccountName.query({
acctName: $scope.accountName,
acctRole: acctRoleParams,
acctRole: acctRoleParams2
});
希望有人遇到过同样的问题?有什么想法吗?
根据我对其他 post 所做的研究,您似乎无法使用 $resource 动态生成。我的工作解决方案是切换到 $http,这样我就可以动态生成多个 acctRole[] 参数:
var acctRoleParams = '';
if(corporate === true)
{
acctRoleParams = '&acctRole[]=C';
};
if(smallBiz === true)
{
acctRoleParams += '&acctRole[]=B';
};
$http.get("https://myRestServiceUrl/services/customer/accounts?acct=" + $scope.account + acctRoleParams)
.success(function (data, status, headers, config) {
$scope.gridOptions.data = data.data.detailsByAcct;
})
.error(function (data, status, headers, config) {
showToast("An error occurred during the request");
})
.finally(function () {
$scope.isGridLoading = false;
});
我想 post 以防其他人一直在努力做同样的事情。