我有以下结构:志愿者VolunteerTrips Trips
志愿者通过volunteerId链接到VolunteerTrips。Trips通过tripId链接到VolunteerTrips。我已经设置了关系,这样我就可以从志愿者那里获得旅行列表,反之亦然。我现在想要的是一个远程方法,它可以将这些行程连接到一个列表中。
例如,值为1 (volunteerId)的/Volunteers/tripList将返回"belize秘鲁“。因此,远程方法将调用/Volunteers/1/trips,遍历该列表,并构建tripName属性的字符串,然后返回该字符串。
查看文档,我看到向volunteers.js添加了类似于以下内容的内容:
module.exports = function(Volunteers) {
Volunteers.tripList = function(volunteerId, cb) {
cb(null, "belize madagascar");
}
Volunteers.remoteMethod(
'tripList',
{
accepts: {arg: 'volunteerId', type: 'string'},
returns: {arg: 'tripList', type: 'string'}
}
);
};然而,我被困在如何进行额外的调用来获取trips,然后循环并构建我的字符串。有人能帮我吗?
发布于 2015-08-19 05:38:07
你看过我的例子了吗:https://github.com/strongloop/loopback-example-app-logic?试一试,如果你再遇到问题就告诉我。
https://stackoverflow.com/questions/32078934
复制相似问题