-1

ionic1 angular js ng-repeat |過濾器:搜索不工作?

angular.module('starter.services', []) 
 

 
.factory('Chats', function($http) { 
 
    // Might use a resource here that returns a JSON array 
 

 
    // Some fake testing data 
 
    var chats=[]; 
 
$http({ 
 
    method: 'GET', 
 
    url: 'js/champions.json' 
 
}).then(function success(data) { 
 
    for (var i = 1; i < 700; i++) { 
 
    if (data.data.data[i]!=undefined) { 
 
     chats.push(data.data.data[i]) ; 
 
    //console.log(data.data.data[i]); 
 
    } 
 
    } 
 
}); 
 
//console.log(chats); 
 
    return { 
 
    all: function() { 
 
     return chats; 
 
    }, 
 

 
    remove: function(chat) { 
 
     chats.splice(chats.indexOf(chat), 1); 
 
    }, 
 
    
 
    get: function(chatId) { 
 
     for (var i = 0; i < chats.length; i++) { 
 
     if (chats[i].id === parseInt(chatId)) { 
 
      return chats[i]; 
 
     } 
 
     } 
 
     return null; 
 
    } 
 
    }; 
 
}) ;
<ion-view view-title=" Tüm Kahramanlar"> 
 
    <ion-content> 
 
    <ion-list> 
 

 
    <ion-item> 
 
    <ion-label fixed>Arama</ion-label> 
 
    <input type="text" style="width: 100%" placeholder="Karakter Adına Göre Filtrele" ng-model="search" ></input> 
 
    </ion-item> 
 

 
</ion-list> 
 
    <ion-list> 
 
     <ion-item class="item-remove-animate item-avatar item-icon-right" ng-repeat="chat in chats | orderBy : 'key' | filter : search " type="item-text-wrap" href="#/tab/chats/{{chat.id}}"> 
 
     <img ng-src="http://ddragon.leagueoflegends.com/cdn/7.18.1/img/champion/{{chat.image.full}}"> 
 
     <h2>{{chat.name }}</h2> 
 
     <p>{{chat.title}}</p> 
 
     <i class="icon ion-chevron-right icon-accessory"></i> 
 

 
     <ion-option-button class="button-assertive" ng-click="remove(chat)"> 
 
      Delete 
 
     </ion-option-button> 
 
     </ion-item> 
 
    </ion-list> 
 
    </ion-content> 
 
</ion-view>

,大家好,我怎麼能過濾該NG重複代碼的未來像什麼都沒有發生。所以它沒有被過濾。請幫我:(我認爲它的模型覺得沒有改變,當我寫|過濾器:「NameSomething」的工作,但我不能在那裏得到納克模型哪能做到這一點:

its my output.

回答

0

嘗試什麼樣的?這樣的:

改變這一行:(請務必在控制器定義$scope.search = {};

<input type="text" style="width: 100%" placeholder="Karakter Adına Göre Filtrele" ng-model="search.name" ></input> 

簡單實現: 搜索與正AME:

<input type="text" ng-model="searchData.name"> 
<div ng-repeat="chat in chats | filter:searchData"> {{chat.name}}</div> 

工作演示:

https://plnkr.co/edit/t6B6fZDRCSLuBN36GLVD?p=preview

+0

對不起的人其不工作納克重複工作,但沒有過濾。 –

+0

謝謝。我試過並嘗試過。非常感謝你 。我有什麼問題。我應該向過濾器發送一個數組嗎? –

+0

是的,你需要發送對象 –