2016-07-17 1 views
1

角度フィルタが新しくなりました。角度フィルタを使用した電子メールIDの並べ替え

フィルタを適用してng-repeatにある電子メールIDを並べ替える場合は、これを行う方法?例えば

[email protected][email protected][email protected][email protected]私のメールです。私は

[email protected][email protected][email protected][email protected]

そのような

として出力を取得したい

アルファベット順でも昇順でも並べ替えることができます。

このために作業コードが提供されていると本当に感謝します。

ありがとうございます。私はOrderByで書くべきもの: "???????"

コード:

<div class="col-md-12 " ng-repeat="e in allEmails | orderBy:'??????'"> 
    //Display the emails here in sorted alphabetically ascending order. 
</div> 
+1

ORDERBY 'のtoString()' –

答えて

3

ここ

var app = angular.module('myapp', []); 
 

 
app.controller('MainCtrl', function($scope) { 
 
    
 
    $scope.emails = ['[email protected]', '[email protected]', '[email protected]', '[email protected]'] 
 
    
 
    
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 

 

 
<body ng-app="myapp" ng-controller="MainCtrl"> 
 
    
 
    <ul> 
 
     <li ng-repeat="email in emails |orderBy:'toString()'"> 
 
     {{email}} 
 
     </li> 
 
    </ul> 
 
    </body>

+0

私はここに奇妙な問題を抱えています。私はexcelファイルから電子メールをエクスポートしています。いくつかの理由のために、それはすべての電子メールをソートしていません。誰でもこのことを教えてください。 – user1851003

+0

たとえば、電子メールがこのような場合は、[email protected]、[email protected]、[email protected]、[email protected]、[email protected]、[email protected] 。私が得ている出力は、[email protected]、[email protected]、[email protected]、[email protected]です。 [email protected]、[email protected] – user1851003

+0

私は助けを得ることができますか??? – user1851003

1

、これを試してみてはcustom filtermySortFilterを作成する別の応答である:

angular 
 
    .module('myapp', []) 
 
    .filter('mySortFilter', function() { 
 
    return function(input) { 
 
     return input.sort(); 
 
    } 
 
    }) 
 
    .controller('MainCtrl', function($scope) { 
 
    $scope.emails = ['[email protected]', '[email protected]', '[email protected]', '[email protected]'] 
 
    });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 

 
<body ng-app="myapp" ng-controller="MainCtrl"> 
 
    <ul> 
 
    <li ng-repeat="email in emails | mySortFilter"> 
 
     {{email}} 
 
    </li> 
 
    </ul> 
 
</body>

1

orderBy: email
あなただけの変数の名前で注文する必要があります。昇順はデフォルトです。 あなたの変数が$scope.email.addresses = []; たなら、あなたはこのようにフィルタリングする必要があります:

orderBy: email.addresses

+0

の前に来る文字列を$ scope.email ... orderBy: "?????????????????????????? – user1851003

+0

私が答えたとおり:email –

関連する問題