angular - Angular 材质树格式问题
问题描述
在 Angular Tree 中,我正在从数据库中检索数据,但树格式与预期不符。下面是浏览器树视图。
根据上图,在国家节点中,我得到了子项中的每个元素,但我只想要不同的项,即单个印度项和单个澳大利亚项。
下面是我的组件代码:
GetTreeValue(): void {
debugger
this._StudentService.getRegionList(1,2).subscribe(data=>{
this.RegionList=data;
let tree_data:any=[];
let country:any=[];
let state:any=[];
let district:any=[];
let region:any=[];
data.forEach(elem=>{
let country_node:any={
name:elem.Country
}
country.push(country_node);
let state_node:any={
name:elem.State
}
state.push(state_node);
let district_node:any={
name:elem.District
}
district.push(district_node);
let region_node:any={
name:elem.Region
}
region.push(region_node);
});
let root_obj:any={
name:'data',
children:[
{
name: 'Country',
children: country
},
{
name: 'State' ,
children:state
},
{
name: 'District' ,
children: district
},
{ name: 'Region' ,
children: region
}]
};
TREE_DATA.push(root_obj);
this.dataSource.data =TREE_DATA;
});
}
解决方案
推荐阅读
- recursion - 联合所有递归 CTE postgresql 中的语法错误
- javascript - 如果在输入字段内按下向上和向下,则聚焦项目
- jquery - Jquery 表附加一个 href 电话
- c - C中的翻译环境和执行环境是什么,它们之间有什么区别?
- ios - RxDataSources 不更新节标题标题
- java - 可以将jsp代码作为参数传递吗?
- python - 熊猫数据框连接非连接轴未对齐
- android - 将存储为字符串的日期转换为日期并仅提取其中的年份
- java - 使用 % sybol 括号内的模式匹配
- asp.net-core - 如何为 SignInManager 设置模拟模式
在 .net 核心中