2016-12-29 98 views
1

我有一个价格标签的项目列表,我有一个选择在顶部的选项,现在我想显示价格比选定的选项更多的项目。这是我的代码,如果我选择10000然后我会得到超过10000的所有项目,但我也有几个项目小于10000例如:6520,9200等。我认为它只比较第一个数字,请让我知道我哪里错了。 谢谢。离子2:筛选

 <ion-item> 
     <ion-label>Price</ion-label> 
     <ion-select [(ngModel)]="pricefilter"> 
      <ion-option value="1000">more than 1000</ion-option> 
      <ion-option value="5000">more than 5000</ion-option> 
      <ion-option value="10000">more than 10000</ion-option> 
      <ion-option value="15000">more than 15000</ion-option> 
      <ion-option value="20000">more than 20000</ion-option> 
     </ion-select> 
     </ion-item> 

    <div *ngFor = ' let content of data ' > 
     <ion-card *ngIf=" ( pricefilter=='' || pricefilter <= content.price) " > 
     <ion-card-content>  
      <h1> {{ content.price }} 
     </ion-card-content> 
     </ion-card> 
    </div> 
+2

难道你的过滤器,价格或两者都是字符串?尝试使用Number(pricefilter)和Number(content.price)来确保您正在比较数字。 –

回答

2

雅尝试这个

<ion-card *ngIf="(pricefilter=='' || pricefilter <= content.price*1)"> 

content.price * 1这会使它成为一个数字,这将分叉罚款

+1

谢谢你这个工作正是我想要的:) – inoxe

+0

为什么你只是发表相同的答案!!!!!!!? –

2

的快速方法是这样的:

<ion-card *ngIf="(pricefilter=='' || pricefilter <= content.price*1)"> 

,但你可以转换content.price在TS文件

+0

谢谢你这个工作。 :) – inoxe