Javascript Angular2管道动态值未采用

Javascript Angular2管道动态值未采用,javascript,angular,typescript,ionic-framework,ionic2,Javascript,Angular,Typescript,Ionic Framework,Ionic2,我有一个类似这样的json [{ "id": 9156, "slug": "chicken-seekh-wrap", "type": "dish", "title": "Chicken Seekh Wrap", "cuisine_type": [2140] }, { "id": 9150, "slug": "green-salad", "type": "dish", "title": "Green Salad", "cuisine_type": [2141

我有一个类似这样的json

[{
  "id": 9156,
  "slug": "chicken-seekh-wrap",
  "type": "dish",
  "title": "Chicken Seekh Wrap",
  "cuisine_type": [2140]
},
{
  "id": 9150,
  "slug": "green-salad",
  "type": "dish",
  "title": "Green Salad",
  "cuisine_type": [2141]
}]
<ion-card *ngFor="let cat of selectedCats">
            <ion-card-header>
              {{cat}}
            </ion-card-header>
            <ion-card-content>
                <ion-list class="checkbox-list" *ngIf="dishes ?.length > 0">
                  <ion-item class="checkbox-item" *ngFor="let dish of dishes | filter:cat">

                    <ion-label>{{dish.title}}</ion-label>
                      <ion-checkbox [formControlName]="dish.id"></ion-checkbox>

                  </ion-item>
                </ion-list>
            </ion-card-content>
</ion-card>
我在angular2中创建了一个这样的管道,可以根据烹饪类型进行过滤

@Pipe({
      name: 'filter',
      pure: false
 })
 export class FilterPipe implements PipeTransform {
     transform(items: any[], selectedId: any): any {
     if(selectedId === -1)
           return items;
    return items.filter(item => item.cuisine_type[0] === selectedId);

  }
 }
从爱奥尼亚的观点来看,我是这样用的

[{
  "id": 9156,
  "slug": "chicken-seekh-wrap",
  "type": "dish",
  "title": "Chicken Seekh Wrap",
  "cuisine_type": [2140]
},
{
  "id": 9150,
  "slug": "green-salad",
  "type": "dish",
  "title": "Green Salad",
  "cuisine_type": [2141]
}]
<ion-card *ngFor="let cat of selectedCats">
            <ion-card-header>
              {{cat}}
            </ion-card-header>
            <ion-card-content>
                <ion-list class="checkbox-list" *ngIf="dishes ?.length > 0">
                  <ion-item class="checkbox-item" *ngFor="let dish of dishes | filter:cat">

                    <ion-label>{{dish.title}}</ion-label>
                      <ion-checkbox [formControlName]="dish.id"></ion-checkbox>

                  </ion-item>
                </ion-list>
            </ion-card-content>
</ion-card>
当我使用管道值作为静态时,就像它的工作状态一样

 <ion-item class="checkbox-item" *ngFor="let dish of dishes | filter:2140">
但当我动态使用它时,它不会显示任何结果

<ion-item class="checkbox-item" *ngFor="let dish of dishes | filter:cat">

问题不是由角度引起的,而是由代码引起的

item.cuisine_type[0] === selectedId
对公认的价值过于具体

item.cuisine_type[0] == selectedId 
通过在比较之前允许类型强制,更容易原谅

这意味着,cat可能是一个字符串“2140”,item.u输入[0]一个数字。
如果您将其作为| filter:2140传递,它将作为数字传递并与项匹配。输入[0]。

即使没有纯:false,也应该可以。是的。但不知道我犯了什么错误。不工作浏览器控制台中有错误吗?不添加控制台。记录“过滤器”,选择EDID;转换内的第一行是否按预期打印?否,其预期结果为过滤器2140。无错误转换中==selectedId而不是===selectedId如何?明白了。谢谢