1 | import { TreeNode } from 'primeng/primeng';
|
2 | import { RefBean, Selectable, RefBeanTreeNode } from './models';
|
3 |
|
4 | export class PrimengUtils {
|
5 | |
6 |
|
7 |
|
8 |
|
9 | public static treeNodesToRefBeans(treeNodes: TreeNode[]): RefBean[] {
|
10 | let refBeans: RefBean[] = new Array<RefBean>();
|
11 | for (let tnode of treeNodes) {
|
12 | refBeans.push(new RefBean(tnode.data, tnode.label));
|
13 | }
|
14 | return refBeans;
|
15 | }
|
16 | |
17 |
|
18 |
|
19 |
|
20 | public static getSelectedTreeNodeByDatas(tree: TreeNode[], datas: string[]): TreeNode[] {
|
21 | let seletedTreeNodes: TreeNode[] = new Array<TreeNode>();
|
22 | PrimengUtils.getSelectedTreeNodeByDatas1(tree, datas, seletedTreeNodes);
|
23 | return seletedTreeNodes;
|
24 | }
|
25 | private static getSelectedTreeNodeByDatas1(treeNodes: TreeNode[], datas: string[], seletedTreeNodes: TreeNode[]) {
|
26 | for (let tnode of treeNodes) {
|
27 | for (let data of datas) {
|
28 | if (data == tnode.data) {
|
29 | seletedTreeNodes.push(tnode);
|
30 | break;
|
31 | }
|
32 | }
|
33 | if (tnode.children) {
|
34 | PrimengUtils.getSelectedTreeNodeByDatas1(tnode.children, datas, seletedTreeNodes);
|
35 | }
|
36 | }
|
37 |
|
38 | }
|
39 | |
40 |
|
41 |
|
42 |
|
43 |
|
44 | public static getSelectedTreeNodes(tree: TreeNode[], refBeans: RefBean[]): TreeNode[] {
|
45 | let seletedTreeNodes: TreeNode[] = new Array<TreeNode>();
|
46 | PrimengUtils.getSelectedNodes(tree, refBeans, seletedTreeNodes);
|
47 | return seletedTreeNodes;
|
48 | }
|
49 | private static getSelectedNodes(treeNodes: TreeNode[], refBeans: RefBean[], seletedTreeNodes: TreeNode[]) {
|
50 | for (let tnode of treeNodes) {
|
51 | for (let rbean of refBeans) {
|
52 | if (rbean.code == tnode.data) {
|
53 | seletedTreeNodes.push(tnode);
|
54 | break;
|
55 | }
|
56 | }
|
57 | if (tnode.children) {
|
58 | PrimengUtils.getSelectedNodes(tnode.children, refBeans, seletedTreeNodes);
|
59 | }
|
60 | }
|
61 |
|
62 | }
|
63 | |
64 |
|
65 |
|
66 |
|
67 |
|
68 | static refBeanTreeNodesToTreeNodes(rNodes: RefBeanTreeNode[]): TreeNode[] {
|
69 |
|
70 | for (let rnode of rNodes) {
|
71 | let tnode: TreeNode = rnode;
|
72 | tnode.data = rnode.code;
|
73 | tnode.label = rnode.name;
|
74 |
|
75 | if (rnode.children) {
|
76 | tnode.children = PrimengUtils.refBeanTreeNodesToTreeNodes(rnode.children);
|
77 | }
|
78 | }
|
79 | return rNodes;
|
80 | }
|
81 | } |
\ | No newline at end of file |