那么,我有一个用户模型,需要实现customToJSON并删除被返回的json对象的密码。 当我把“responseType”作为“json”放在“exit”中时,一切都很好,并且密码从响应中取出。但是,根据发送responseType为空的终端中的消息,将不推荐使用responseType:“json”,但不调用customToJSON。任何人都可以帮我理解这个吗?Sails 1.0,如何从Action2调用customToJSON?
这是型号代码:
[...]
attributes: {
name: {
type: 'string',
required: true,
},
email: {
type: 'string',
required: true,
},
password: {
type: 'string',
minLength: 6,
required: true,
},
},
customToJSON: function() {
return _.omit(this, ['password']);
},
[...]
这是动作代码:
module.exports = {
friedlyName: 'Users List',
description: 'User list -> all users',
exits: {
success: {
}
},
fn: async (inputs, exits) => {
var users = await User.find();
return exits.success(users);
}
}
是,如果你把 “的responseType: 'JSON'”:消息
json
响应类型将在即将发布的版本中弃用。
我喜欢这个解决方案。但从我的理解来看,这似乎是一个仍然没有解决的问题,因为框架应该提供本地的。你可以在 https://trello.com/c/5SkpUlhI/402-make-customtojson-work-with-actions2 中看到这个,代表官方帆队js的trello js - > v1 –
是的,你是对的...但仍然,我更喜欢这个...代码是更加maintanable然后:) – hlozancic