【问题标题】:How to prevent Ember Data from saving a read-only attribute for ActiveModelSerializer如何防止 Ember Data 为 ActiveModelSerializer 保存只读属性
【发布时间】:2017-11-29 18:53:12
【问题描述】:

我正在尝试将{readOnly: true} 功能与ActiveModelSerializer 一起使用,方法是自定义序列化方法以忽略只读属性,例如JSONAPISerializerthisRESTSerializerthis,以提前节省上传带宽。

有谁知道ActiveModelSerializer是否可以做类似的事情?

【问题讨论】:

    标签: ember.js ember-data activemodel active-model-serializers


    【解决方案1】:

    ActiveModelSerializerJSONAPISerializer 都扩展了 JSONSerializerserializeAttribute 方法继承自 JSONSerializer。所以我看不出有什么理由你不能采用你已经提到的this stackoverflow question 中给出的解决方案。

    other answer on stackoverflow 依赖于一个非常旧的 API 版本的 RESTSerializer,它在 ember-data 1.x 版本之前已被删除。 another answer to same question中也提到了这一点。

    【讨论】:

      猜你喜欢
      • 2022-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多