我正在努力将变量的值作为关键字传递给Angularjs应用程序中使用$ resource的GET查询参数:
以下是代码:
//控制器
..
.
var value = obj.value; // Y
var category = obj.category; //ctrlpart
//category contains a dynamic value which needs to go as a key
..
.
scope.materialDataPromise = MaterialData.query(
{
"query" : keyword,
"ftype" : ftype,
category : value,
"start" : 0,
"rows" : 1000
}, function(response) {
这样请求看起来像
http://test.com:8080/JunkAPI/MaterialServlet?query=0091&start=0&rows=1000&crtclpart=Y
&安培; crtclpart = Y
带有多个动态值的OR
http://test.com:8080/JunkAPI/MaterialServlet?query=0091&start=0&rows=1000&crtclpart=Y&invoice=ALL
&安培; crtclpart = Y&安培;发票= ALL
以下是服务电话:
apiService.factory("MaterialData", function ($resource) {
var _url = "http://test.com:8080/JunkAPI/MaterialServlet;
return $resource(_url, {}, {
"query": {
method: "GET",
headers: {
'Content-Type': 'application/json'
}
}
});
});
请建议一些选项来处理这个问题,以便在$ resource rest api调用中将多个动态值作为键传递
答案 0 :(得分:0)
var propName = 'crtclpart';
var value = 'Y';
var obj = {};
obj[propName ] = value;
scope.materialDataPromise = MaterialData.query(obj);