mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
demo(collection-repeat): only show letters that match searched names
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
<title>Collection-Repeat: Early Preview</title>
|
||||
|
||||
<link href="http://code.ionicframework.com/nightly/css/ionic.min.css" rel="stylesheet">
|
||||
<script src="http://code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
|
||||
<script src="http://code.ionicframework.com/nightly/js/ionic.bundle.min.js"></script>
|
||||
<link href="style.css" rel="stylesheet">
|
||||
<script src="script.js"></script>
|
||||
<script src="contacts.js"></script>
|
||||
|
||||
@@ -31,10 +31,24 @@ function MainCtrl($scope, $ionicScrollDelegate, filterFilter) {
|
||||
}
|
||||
|
||||
$scope.getContacts = function() {
|
||||
var contactsByLetter = {};
|
||||
return contacts.filter(function(item) {
|
||||
return !$scope.search || item.isLetter ||
|
||||
var itemDoesMatch = !$scope.search || item.isLetter ||
|
||||
item.first_name.toLowerCase().indexOf($scope.search.toLowerCase()) > -1 ||
|
||||
item.last_name.toLowerCase().indexOf($scope.search.toLowerCase()) > -1;
|
||||
|
||||
if (!item.isLetter && itemDoesMatch) {
|
||||
var letter = item.last_name.charAt(0).toUpperCase();
|
||||
contactsByLetter[letter] = contactsByLetter[letter] || 0;
|
||||
contactsByLetter[letter]++;
|
||||
}
|
||||
|
||||
return itemDoesMatch;
|
||||
}).filter(function(item) {
|
||||
if (item.isLetter && !contactsByLetter[item.letter]) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user