2016-10-18 2 views
1

これは、Angularのng-repeatディレクティブを使用してhtmlでレンダリングするサンプルJsonです。

[ 
    { 
    "id": "10.0.0.208", 
    "ip_address": "10.0.0.208", 
    "username": "root", 
    "password": "--invalid secret key--", 
    "ports": [ 
     8056, 
     8057 
    ], 
    "installations": 2, 
    "created": "2016-07-15 17:41:36", 
    "wanpipe": { 
     "wp1": { 
     "port": 8056, 
     "physical": true, 
     "signalling": true, 
     "outgoing": true, 
     "hangup_cause": "NORMAL_CLEARING", 
     "outgoing_caller_id": "1409716078" 
     }, 
     "wp2": { 
     "port": 8056, 
     "physical": true, 
     "signalling": true, 
     "outgoing": true, 
     "hangup_cause": "NORMAL_CLEARING", 
     "outgoing_caller_id": "1409716077" 
     }, 
     "wp3": { 
     "port": 8056, 
     "physical": true, 
     "signalling": true, 
     "outgoing": true, 
     "hangup_cause": NORMAL_CLEARING","outgoing_caller_id":"1409716077" 
    } 
] 

属性ip_addressに角度フィルタを呼び出すことで、HTMLで検索バーを作成しました。これは次のとおりです。それは動作し、ng-repeatを使って再度繰り返すことができるpagedItemsというフィルタリングされた配列を私に返します。

$scope.figureOutIPToDisplay = function(searchIP) { 
     console.log(searchIP); 
     $scope.filteredItems = $filter('filter')($scope.json.json, { 
      ip_address : $scope.searchIP 
     }); 

     $scope.pagedItems = $scope.filteredItems; 
     console.log($scope.pagedItems); 

    }; 

以下は、HTMLコードである

<div class="row" ng-repeat=" init in pagedItems "> 
<div ng-repeat="(key,wanpipe) in init.wanpipe" class=" col-lg-1 col-md-1 col-sm-4 col-xs-4 "> 
             <button popover-trigger="focus" uib-popover-template="templateUrl" ng-if="wanpipe.physical==true"type="button" class="btn btn-primary" >{{key}}</button> 

             <button popover-trigger="focus" uib-popover-template="templateUrl" ng-if="wanpipe.physical==false" type="button" class="btn btn-danger">{{key}}</button> 

             <script type="text/ng-template" id="myPopoverTemplate.html"> 
              <div class="row ipAddressdetails"> 
               <div class="col-lg-12 col-md-12 text-center"> 
                <span class="glyphicon glyphicon-random"></span> Port: {{wanpipe.port}} 
               </div> 
              </div> 
              <div class="row ipAddressdetails"> 
               <div class="col-lg-12 col-md-12 text-center"> 
                <span class="glyphicon glyphicon-time"></span> Physical: {{wanpipe.physical}} 
               </div> 
</div> 

しかしながら、前述JSONで、IはまたWANPIPEオブジェクトの一部であるポート属性に基づいてフィルタリングすることを試み、ポート属性を持つwp1、wp2、wp3などの他のオブジェクトで構成されています。 私はそれを動作させるために多くのことを試しましたが、悲惨なことには失敗しました。どんな助けも大歓迎です。

答えて

3

ディープフィルタを実行するには、実際のプロパティ名の代わりに$記号を使用します。あなたは、オブジェクトのすべてのプロパティに深い検索したいのであれば、あなたは

From angularjs documentationを使用することができます。

注名前のプロパティは、特別な$プロパティながら、唯一の同じレベル のプロパティを一致すること同じ のプロパティと一致します。例えば。 {name:{最初: 'John'、最後: 'Doe'}}の配列アイテムは{name: 'John'}と一致しませんが、 {$: 'John'}

と一致します

$scope.filteredItems = $filter('filter')($scope.json.json, { 
      $: $scope.searchIP 
     }); 
しかしながら、前述JSONに、私はまた、順番に、すなわちWP1の他のオブジェクトで構成さWANPIPEオブジェクト、 の一部であるポート属性の 基づいてフィルタリングする試みwp2、wp3など ポート属性を持つ。

これは、ご使用のシナリオでは有効です。これは、wanpipeのプロパティのみを調べます。

$scope.filteredItems = $filter('filter')($scope.json.json, { 
      wanpipe: {$: $scope.searchIP} 
     }); 
関連する問題