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