角材质树-不同的父/子类型 [英] Angular Material Tree - Different parent/child types

查看:51
本文介绍了角材质树-不同的父/子类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以利用材料树来表示父/子数据结构,其中子级与父级具有不同的数据形状?我对这个组件的经验似乎表明,数据结构需要是相同类型的递归.但是,我想用它来表示诸如订单(父项)和订单项(子项)之类的结构.这似乎不是受支持的用例.正确吗?

Is there a way to utilize a material tree to represent parent/child data structures where the child has a separate data shape than the parent? My experience with this component seems to indicate that the data structure needs to be a recursion of the same type. However, I would like to use it to represent structures such as Orders (parent) with Order Items (children). This does not seem to be a supported use case. Is that correct?

自从v2推出以来,我一直在使用Angular,并且自开始以来就一直在使用Angular Material.我认为,Tree组件似乎是最麻烦的组件,也是最难于采样的代码.

I've been using Angular since the v2 rollout and I've been using Angular Material since inception. In my opinion, the Tree component seems to be the most cumbersome component with the most difficult to sample code.

推荐答案

我遇到了同样的问题,我选择的解决方案是为树组件制作一个扁平的结构.结构具有来自父级和子级的所有字段(如果在父级上使用模型,则子级字段将为空,而在子节点上则相反).似乎工作正常.

I had the same issue, the solution I chose was to make a flatten structure just for tree component. Structure have all the fields from parent and child (if model is used on parent, child fields remain empty and opposite on child node). Seems to work just fine.

发件人:

export interface ParentModel{
  id: number;
  name: string;    
  child: ChildModel[];    
}

export interface ChildModel{
  id: number;
  symbolName: string;    
  description: string;    
}

收件人:

export interface TreeModel {
  id: number;
  name: string; 
  symbolName: string;
  description: string;

}

这篇关于角材质树-不同的父/子类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆