angular2 - 剑道过滤器不起作用

时间:2017-08-26 09:39:11

标签: angular filter status

我在角度2过滤方面遇到了问题。我在onSelectStatus时得到了空数组。谁能告诉我我错过了什么?这是我的代码:

app.component.html



<select [(ngModel)]="status" (change)="onSelectStatus(status)" class="form-control" id="status" name="status">
  <option *ngFor="let status of statuses" [ngValue]="status.value">{{status.value}}</option>
</select>
&#13;
&#13;
&#13;

app.component.ts

&#13;
&#13;
status: number;
statuses = [];
selected;
selectedData;

ngOnInit() {

  console.log(this.userId);
  this.http.post(this.host + '/api/v1.0/merchant/mini-statement', {
      'datefrom': '2017-05-27',
      'dateto': '',
      'userId': this.userId
    })
    .map(res => res.json())
    .subscribe(data => {
      this.items = data;
      console.log(this.items);
      this.loadItems();
    }, error => {
      console.log(error);
    });

  this.statuses = [{
      id: 1,
      value: 'Successful',
    },
    {
      id: 2,
      value: 'Voided',
    }
  ];

}

constructor(private http: Http) {
  this.selectedData = this.items;
}

protected pageChange(event: PageChangeEvent): void {
  this.skip = event.skip;
  this.loadItems();
}

onSelectStatus(val) {
  console.log(val);
  this.selectedData = this.items.filter(x => x.status == val);
  console.log(this.selectedData);

}
&#13;
&#13;
&#13;

data.json

enter image description here

2 个答案:

答案 0 :(得分:2)

您已将状态声明为数字,但其类型为对象,具有id和value。

将其更改为您的状态类型

status: Status;

并将模型更改为,

<select [(ngModel)]="status.value" (change)="onSelectStatus(status)" class="form-control" id="status" name="status">

相应的ts将是,

onSelectStatus(stat) {
  console.log(stat);
  this.selectedData = this.items.filter(x => x.status == stat.value);
  console.log(this.selectedData);

}

答案 1 :(得分:0)

以下是我对此问题的修正:

&#13;
&#13;
=RIGHT(A2,LEN(A2)-FIND(">",A2))
&#13;
&#13;
&#13;