var loopback = require('loopback');
var serviceOffering = loopback.getModelByType('ServiceOffering');
var app = require('../../server/server.js');
module.exports = function (serviceOffering) {
serviceOffering.GetAllOfferings = function (options,category,callback) {
var filter = JSON.parse(JSON.stringify(category));
var arry=[];
var getOrgFil={where:{or:[]}};
var uniqOrList=[];
serviceOffering.find(options,filter, function (err, result) {
for(var i = 0; i < result.length; i++) {
var obj = result[i];
if (arry.indexOf(result[i]._createdBy) === -1) {
arry.push(obj._createdBy);
getOrgFil.where.or.push({UserName:obj._createdBy});
}
}
console.log(getOrgFil);
serviceOffering.app.models.Realm.find(options,getOrgFil, function (err, resl) {
console.log(resl);
return callback(null, resl);
});
});
};
serviceOffering.remoteMethod(
'GetAllOfferings', {
http: { path: '/GetAllOfferings', verb: 'get' },
accepts: { arg: 'category', type: 'object',http: { source: 'query' } },
returns: { type: 'array', root: true }
});
}
&#13;
我打电话给&#39; Realm&#39;来自我的服务提供商的模型&#39;模型的远程方法来过滤和获取一些数据。但我得到的响应是#34;未定义&#34;。我是环回的新手,对如何调试的想法非常有限。我能够打印&#34;结果&#34;,&#34; getOrgFil&#34;,但是&#34; resp&#34;来自&#39; undefined&#39;。有人可以帮我理解为什么我会得到&#39; undefined&#39;当我试图通过远程方法获取resp的值?
I get output as mentioned below
result = [ { SeriviceCategory: 'SCCER',
AssetType: List [ 'ATCOF', 'ATHUS', 'ATMLK' ],
ServiceType: List [ 'STQCR' ],
Identity: null,
_type: 'ServiceOffering',
_createdBy: 'admin',
_modifiedBy: 'admin',
_createdOn: 2018-01-01T09:21:48.638Z,
_modifiedOn: 2018-01-01T09:21:48.638Z,
_scope: List [ 'tenantId:default' ],
_autoScope: { tenantId: 'default' },
_isDeleted: false,
_version: '536c3db2-2323-4004-afb6-2a9e7995aeca',
id: 5a49fdac28a2bd802d8206ba } ]
getOrgFil = { where: { or: [ [Object] ] } }
stringified getOrgFil = {"where":{"or":[{"UserName":"admin"}]}}
resl = undefined
&#13;
Realm&amp; ServiceOffering Models。
答案 0 :(得分:0)
将是这个
<script type="text/javascript">
function change(el) {
if (el.value === "P")
el.value = "A";
else
el.value = "P";
}
</script>