如何为条件绑定编写管道过滤器

时间:2018-06-30 02:45:51

标签: typescript angular2-forms angular4-forms angular2-filtering

在这种情况下,我绑定值

        this.employees = [
  {code: 'emp101', Job:'B', dateOfBirth: '25/6/1988'},
{ code: 'emp102',Job:'E', dateOfBirth: '9/6/1982'},

我在这里将数据绑定到表中

<input type="text" (keyup)="Somevale($event.target.value)"/>
 <thead>
        <tr>
            <th>Code</th>
            <th>JObType</th>
            <th>Date of Birth</th>
        </tr>
    </thead>
    <tbody>
        <tr *ngFor='let employee of pagedItems'>
            <td>{{employee.code}}</td>
            <td>{{(employee.Job == 'E')? 'Employee' : (employee.Job == 'B') ? 'Business' : (employee.Job == 'U') ? 'Un-Employeed' : (employee.Job == 'D') ? 'Department' : '' }}</td>
            <td>{{employee.dateOfBirth}}</td>

        </tr>
    </tbody>

这是我在KEYUP中写的“我的搜索功能”

items:any[];
Somevale(searchText:string){
    this.items=this.allItems;  //Here im Assigning mty data to this.items
        if(!this.items) return [];
        if(!searchText) return this.items;
    searchText = searchText.toLowerCase();
    return  this.pagedItems= this.items.filter( it => {
          return it.code.toLowerCase().includes(searchText) || it.Job.toLowerCase().includes(searchText =='Employee');;
        });
       }

这对ID和名称都有效,但是我尝试4r Job遇到错误

0 个答案:

没有答案