2016-04-23 62 views
0

這就是我正在做的。 我所說的REST API返回響應以這種格式創建多個表時智能表搜索不起作用

「元語言」:{ 「1」:{ 「ID」:1, 「名稱」: 「阿布哈茲」 }, 「2」: { 「ID」:2, 「名」: 「遠方」 }} , 「製造商」:{ 「-1」:{ 「ID」:-1, 「名」: 「所有」 }, 「1」:{ 「id」:1, 「name」:「RIM」 }, 「2」:{ 「ID」:2, 「名」: 「HP」 }}

這基本上是一個地圖字符串和地圖。 我現在必須創建n個表,其中n是原始地圖中的鍵的數量,並且在每個表內必須顯示將是內部地圖的值的數據(「id」:2, 「name」:「HP 「)

我使它工作,但搜索不起作用。 這是我的示例代碼

<div ng-repeat="(key,value) in metadataDetails"> 
<table st-table="metadataCollection" st-safe-src="metadataDetails" class="table table-striped"> 
<thead> 
    <tr class="style_tr"> 
    <th st-sort="name">name</th> 
    <th st-sort="name">name</th> 
    <th st-sort="description">description</th> 
    <th st-sort="countryName">countryName</th> 
    <th st-sort="carrierName">carrierName</th> 
    </tr> 
    <tr class="textSearchTr"> 
    <th colspan="4" class="textSearchTr"> 
    <input class="freshblue" placeholder="Enter value to search/filter" type="text" ng-model="searchParam.search" /> 
    </th> 
    </tr> 
    </thead> 
    <tbody> 
    <tr ng-repeat="row in getValueMap(key)" ng-show="showRow"> 
    <td>{{row.id}}</td> 
    <td>{{row.name}}</td> 
    <td>{{row.description}}</td> 
    </tr> 
    </tbody> 
</table> 
</div> 

而我的JS文件

AuditMetadataService.get({}, function(data) { 

     $scope.numRecord = data.length; 
     $scope.metadataDetails = data; 
     $scope.metadataCollection = [].concat($scope.metadataDetails); 
     console.log("Return value :"); 
     console.log($scope.metadataDetails); 
    }); 

$scope.getValueMap = function(key) { 

     console.log(key); 
     return $scope.metadataDetails[key]; 

    }; 

可能有人請幫助?

回答

0

您可以通過獲取鍵和使用Array.prototype.map函數將地圖對象轉換爲數組,因爲st-sort需要數組項,而不是鍵值。

$scope.tables = keys.map(function(key) { 
    return Object.keys(data[key]).map(function(k) { 
     return data[key][k]; 
    }); 
}); 

然後你可以使用ng-repeat創建的所有表想,單擊列標題現在會正確的對它們進行排序迭代$scope.tables

這是demo

+0

謝謝,這解決了我的問題。 – Pratik