我有一個模型,使用郵遞員我向這個模型發送請求,作為回應我得到了完整的記錄(假設我有 25 列),所以作為回應我得到了 25 列。我只想在回應中看到一列,我該如何更改它。在javascript檔案中,我已經寫了保存前和保存后的方法。
而不是所有列的詳細資訊,我只想要一個列的詳細資訊作為回應,我收到了郵遞員
uj5u.com熱心網友回復:
解決方案 1:
對于一次性請求filter,您可以在 get 請求中傳遞查詢物件,并使用fields指定所需列的選項。
示例:僅回傳id, 和name列。
{
"fields": {
"id": true,
"name": true
}
}
欄位也可以像這樣在服務器端提供:
yourRepository.find({fields: ['id', 'name']});
檔案:https ://loopback.io/doc/en/lb4/Fields-filter.html
解決方案 2:
要禁用在每個請求中回傳列,請hiddenProperties在模型定義中指定
。
像下面這樣:
@model({
settings: {
hiddenProperties: ['password'] // ??
}
})
class MyUserModel extends Entity {
@property({id: true})
id: number;
@property({type: 'string'})
email: string;
@property({type: 'string'})
password: string;
...
}
中指定的屬性hiddenProperties永遠不會在回應中回傳,如果需要,您可以在 js/ts 代碼中訪問它們。
檔案:https ://loopback.io/doc/en/lb4/Model.html#hidden-properties
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/537337.html
標籤:休息环回js环回
下一篇:使用C#回傳System.NullReferenceException的Fiebase規則創建,如何解決此問題?
