那麼,我有一個用戶模型,需要實現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