我想将远程方法的数据类型设置为模型。如果我在User.js中,我可以这样做:
User.remoteMethod('contacts', {
accepts: [
{
arg: 'contacts',
type: User,
}
],
returns: {arg: 'data', type: 'json'}
});
但我有另一个名为Contac的模型,我想用“type:Contact”替换“type:User”。 但是在这种情况下,我认为app对象无法访问,所以如果有任何方法可以做到这一点?
答案 0 :(得分:0)
我认为你想要的类型是'对象'这可以作为一个对象的一切 这取决于你的真实输入。如果您希望POST整个用户或联系人作为json数据,那么' object'建议,或者如果你只想输入一个foreignKey,如" contactId"为了表示联系人,一个id就足够了,因为您可以在远程方法的逻辑代码中获取实例,如:
User.contact = function (contactId, cb){
Contact = User.app.models.Contact // suppose Contact is the so-called another model
Contact.findById(contactId,function(err,instance){
...
cb(null, JSON.stringify(instance); //instance is the contact whose id is contactId
});
}