具有角度2树组件的Filtring函数

时间:2016-12-22 14:20:25

标签: angular

我正在尝试实现angular2-tree组件

https://angular2-tree.readme.io/docs/filtering

到目前为止一切都很好我只想使用过滤功能,我不知道如何激活它。

这是我的代码:

app.component.ts

Promise { [ 
            { name: 'Agriculture' },
            { name: 'engineer' } 
        ] }

tree.component.html

\xD0

但是当我使用我的输入搜索扔我的树时,我得到了这个错误:

    import { Component ,ViewChild} from '@angular/core';
    import { Http, ConnectionBackend, RequestOptions } from "@angular/http";
    import {OdooRPCService } from 'angular2-odoo-jsonrpc';
    import {
      TreeComponent,
      TreeNode,
      TREE_ACTIONS,
      KEYS,
      IActionMapping
    } from 'angular2-tree-component';

    export class ResPartner {
      id: number;
      name: string;
      buyerTree: number[];
    }

    export class ProductCategory {
      id: number;
      name: string;
    }

    @Component({
      moduleId: module.id,
      selector: 'my-app',
      templateUrl: 'tree.component.html',
      providers: [ OdooRPCService],

    })
    export class AppComponent   { 
       // @ViewChild('tree') tree: any;
       @ViewChild(TreeComponent)
       private tree: TreeComponent;

       constructor(public odooRPC: OdooRPCService) {  
          // I construct my tree here 
       }
    }

1 个答案:

答案 0 :(得分:0)

如果有人在寻找答案

    export class AppComponent   { 
       // @ViewChild('tree') tree: any;
       @ViewChild(TreeComponent)
       private tree: TreeComponent;

       constructor(public odooRPC: OdooRPCService) {  
          // I construct my tree here 
       }

      filterNodes(text, tree)                      {
         tree.treeModel.filterNodes(text, true);
       }
 }

事实上,有一个关于项目回购的例子: https://github.com/500tech/angular2-tree- component/tree/master/example/cli/src/app

我们可以找到并例证 app.component.ts