gpt4 book ai didi

ember.js - Ember Docs - 只读嵌套数据

转载 作者:行者123 更新时间:2023-12-02 09:13:46 24 4
gpt4 key购买 nike

我一直在阅读 v2.4 的 Ember 文档,我遇到了一个我不明白的部分:

Some models may have properties that are deeply nested objects of readonly data. The naïve solution would be to define models for each nested object and use hasMany and belongsTo to recreate the nested relationship. However, since readonly data will never need to be updated and saved this often results in the creation of a great deal of code for very little benefit. An alternate approach is to define these relationships using an attribute with no transform (DS.attr()). This makes it easy to access readonly values in computed properties and templates without the overhead of defining extraneous models.

在我的用例中,我只会显示数据,它永远不会保存回服务器。我找到的嵌套数据的每个示例都显示为每个嵌套级别设置单独的模型,然后设置关系,这被称为“简单的解决方案”。那么正确的方法是什么?谁能帮我扩展一下这个吗?提前致谢!

最佳答案

看评论,答案是:

定义根对象并将该对象的字段定义为 DS.attr()。没有类型信息。

您仍然可以使用点表示法访问嵌套数据,但无需再指定任何结构。

请查看以下链接,以更完整地了解此主题。

https://thejsguy.com/2016/01/29/working-with-nested-data-in-ember-data-models.html

关于ember.js - Ember Docs - 只读嵌套数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35833804/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com