2017-02-08 6 views
1

私はJSONを返すデータベースを持っています。私は*ngFor=""に同じページを使用しています。ユーザー名で検索する検索バーがありますユーザーの説明で検索します(入力した単語に矛盾がある場合)。ここで2つの検索結果でフィルターを絞ります

は私のコードです:

マイ検索バー:

<ion-searchbar placeholder="Search..." (ionInput)="searchUser($event)"></ion-searchbar> 

マイsearchUser方法(同じ1つのイオン2つのドキュメントはあなたを与える):

searchUser(ev: any) { 
    // Reset items back to all of the items 
    this.initializeItems(); 

    // set val to the value of the searchbar 
    let val = ev.target.value; 

    // if the value is an empty string don't filter the items 
    if (val && val.trim() != '') { 
    this.items = this.items.filter((item) => { 
     return (item.name.toLowerCase().indexOf(val.toLowerCase()) > -1); 
    }) 
    } 
} 

そして、私のJSON

の例
{ 
    "key": { 
    "name": name, 
    "description": desc, 
    "city": city, 
    "state": state, 
    }, ... 
} 

私がこれまでに試した唯一のことは、返品に&& item.description.toLowerCase().indexOf(val.toLowerCase()) > -1を追加することですが、何も得られません。

これを達成する最良の方法はなんですか?プロバイダとは?私の帰りの正しいコード行?

感謝:)

答えて

1

私はあなたが使うべきだと思うOR ||演算子の代わりと&&
&&には、の名前の説明の両方に一致する結果のみが表示されます。

関連する問題