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

前端之家收集整理的这篇文章主要介绍了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.f2er.com/js/157389.html

猜你在找的JavaScript相关文章