angular / angular/components

mat-tree displaying child value integers as nodes

オープン
#16,815 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る
area: material/tree P4 troubleshooting
主要言語
TypeScript
スター
25k
フォーク
6.8k
平均マージ
1日 8時間
マージ済み PR(30日)
91

説明

I am new to this so please say if this is better posted elsewhere.

I am building a mat-tree on the fly by creating a json string.
The string is:
" {"Politics":[],"Sport":[{"footie":[{"uefa":[]}]},{"sportsub":[]}],"Weather":[{"newdir":[]},{"weathersub":[]}"
It works fine but displays the child level value as an extra level, (see image) how do I lose this?

Code is

private populateTree(workdata) {

var dataObject = JSON.parse(workdata);
// Build the tree nodes from Json object. The result is a list of `FileNode` with nested
// file node as children.
const data = this.buildFileTree(dataObject, 0);
// Notify the change.
this.dataChange.next(data);
}

buildFileTree(obj: { [key: string]: any }, level: number, parentId: string = '0'): FileNode[] {
return Object.keys(obj).reduce((accumulator, key, idx) => {
const value = obj[key];
const node = new FileNode();
node.filename = key;
node.id = `${parentId}/${idx}`;

if (value != null) {
if (typeof value === 'object') {
node.children = this.buildFileTree(value, level + 1, node.id);
} else {
node.type = value;
}
}

return accumulator.concat(node);
}, []);
}

![mat-tree](https://user-images.githubusercontent.com/17275047/63251797-5df06880-c266-11e9-809a-58b753581fe9.png)

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

まず populateTree の JSON を再現し、buildFileTree を追跡します。特に、オブジェクト値がどのように children になり、オブジェクトでない値がどのように node.type になるかを確認します。意図した mat-tree の階層が余分な子値ノードなしで描画されれば完了です。この issue にはリポジトリのファイル名も実行するテストも記載されていません。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
angular, typescript
領域
frontend
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。