2016-06-07 43 views
1

我有以下的角腳本,它什麼也不做,但創建對象的列表:顯示錶NG-單擊當基於ID

//To get the existing records 
$scope.get_records = function(){ 
    filter_data = {set__iexact: $scope.final_data.set}; 
    bin.get(filter_data, 
     function(data){ 
     $scope.main_list = data['objects']; 
     console.log($scope.main_list); 
     angular.forEach($scope.main_list, function(f) { 

     }); 
    },function(data, status){ 
      console.log('Stage1: Internal error while loading initial data:'+status); 
     } 
)}; 

每個記錄的唯一字段是id。我在HTML中將這些ID顯示爲一個表格(tr)。

<table class="table table paleblue table-fixed"> 
    {%verbatim %} 
    <tr align="center" ng-repeat="f in main_list" ng-cloak> 
     <td><button class="btn btn-small">{{f.id}}</button></td> 
    </tr> 
</table> 

我的目標是展現出表的當前td以下,其中只包含特定ID的元素。我怎樣才能做到這一點?如何獲得該特定ID,以便我可以將它與set一起過濾?任何想法?

+0

* 「我怎麼ID爲」 * ...你說'f.id'是不正確的?問題/問題陳述不是很清楚 – charlietfl

+0

f.id是正確的。但我需要獲取該特定ID的對象並顯示在表格中。 :) – vellattukudy

+0

而這樣做的問題是什麼具體? – charlietfl

回答

0

您必須添加:

0 - 過濾器:第二排將有其他元素的ID過濾,在我的情況下,將父親一行。

<tr align="center" ng-repeat="f in main_list" ng-cloak> 

將變更爲

<tr align="center" ng-repeat="f in main_list | filter:{father:selected}" ng-cloak> 

1 - 設置過濾器:當點擊Id set the filter with the id value, in my case I click a custom link, and set the Id as $ scope.selected`此元素在其他行進行過濾:父行。

<td><button class="btn btn-small">{{f.id}}</button></td> 

將變更爲

<td><a ng-click="$parent.selected=element.id">Show sons of {{element.id}}</a></td> 

正如你可以看到我使用$parent.selected。因爲當你在ng-repeat中時,你處於CONTROLLER SCOPE的SUB SCOPE中。

檢查Plunkr:http://plnkr.co/edit/vtsOsBFzDPXEPg3QW5yn?p=preview