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 }
});
}
我正在通过我的'ServiceOffering'模型的远程方法调用'Realm'模型来过滤并获取一些数据。但我得到的响应是“未定义”。我是环回的新手,对如何调试的想法非常有限。我能够打印“result”,“getOrgFil”,但“resp”是“未定义”。当我试图通过远程方法获取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
Realm和Service Offering Models之间没有任何关系。
就是这样
var app = require('../../server/server');
app.models.Realm.find(options,getOrgFil, function (err, resl) { // this instead of serviceOffering.app.models
return callback(null, resl);
});