我已經採取了從角文檔的例子爲Plunker爲了什麼,我試圖做一個快速演示。我所擁有的是名稱和姓氏作爲數組中對象的一部分。當我開始過濾輸入時,它運行良好,直到我輸入名稱後纔開始輸入姓氏。我該如何去做,以便搜索結果將包括姓名和姓氏?我被困在這一點上,無法弄清楚這一點,所以我正在尋找一些幫助。如何重複多個屬性?
<div ng-controller="repeatController">
I have {{friends.length}} friends. They are:
<input type="search" ng-model="q" placeholder="filter friends..." aria-label="filter friends" />
<ul class="example-animate-container">
<li class="animate-repeat" ng-repeat="friend in friends | filter:q as results">
[{{$index + 1}}] {{friend.name}} who is {{friend.age}} years old.
</li>
<li class="animate-repeat" ng-if="results.length === 0">
<strong>No results found...</strong>
</li>
</ul>
</div>
這裏是Plunker:https://plnkr.co/edit/SS2X2ZmguxNxQ4Txz3BN
感謝您提前給任何幫助。
編輯:我正在尋找的是,如果我要鍵入John Doe,結果不會說「找不到結果」。如果我在一個屬性中鍵入,它工作正常,但是一旦我開始執行lastName,就沒有找到結果。
是的,但問題是,如果你鍵入John Doe,它說沒有結果? – pertrai1
這是因爲搜索只搜索一個屬性。你的問題沒有包含任何與'name'和'lastName'搜索相關的內容。 –
這裏是搜索的兩個plunkr,我會更新我的答案:https://plnkr.co/edit/fr3XH3ghMw0hidceXDVx?p=preview –