微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ember.js – Ember Docs – Readonly嵌套数据

我一直在阅读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

原文地址:https://www.jb51.cc/js/157389.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐