2016-04-06 20 views
0

如何獲得組{對象}當一個屬性與[數組]值爲itemSearch, 即時通訊使用_.lodash /下劃線如何獲得組對象時的屬性的值是等於itemSearch

{ 
"tileRecords" : [ 
{ 
"tileName"  : "Fama Brown", 
"tileGroup"  : ["Polished", "Matt", "Rought"], 
"tileDetails" : 
     { 
     "tileSize"   : "60x60", 
     "tileType"   : "Polished" 
     } 
}, 
{ 
"tileName"  : "Fama Nero",  
"tileGroup"  : ["Polished", "Matt", "Rought"], 
"tileDetails" : 
     { 
     "tileSize"   : "60x60", 
     "tileType"   : "Polished" 
     } 
}, 
{ 
"tileName"  : "Dolce Beige", 
"tileGroup"  : ["Italian", "Matt", "Rought"], 
"tileDetails" : 
     { 
     "tileSize"   : "60x60", 
     "tileType"   : "Polished" 
     } 
} 
] 
} 

我如何獲得對象tileName:Fama Brown和Fama Nero在tileGroup中使用值爲「Polished」的過濾器?

由於該組具有唯一的拋光價值。

回答

0

可以使用angular filter代替lodash這是非常簡單的實現, 如果您正在使用NG-重複使用它,請嘗試以下,

<div ng-repeat="tile in tiles.tileRecords | pick: tileGroupFilter"> 
    {{ tile.tileName }} 
</div> 

而在你的控制器

$scope.tiles = { 
         "tileRecords" : [ 
          { 
          "tileName"  : "Fama Brown", 
          "tileGroup"  : ["Polished", "Matt", "Rought"], 
          "tileDetails" : 
           { 
            "tileSize"   : "60x60", 
            "tileType"   : "Polished" 
           } 
          }, 
          { 
           "tileName"  : "Fama Nero",  
           "tileGroup"  : ["Polished", "Matt", "Rought"], 
           "tileDetails" : 
            { 
             "tileSize"   : "60x60", 
             "tileType"   : "Polished" 
            } 
          }, 
          { 
           "tileName"  : "Dolce Beige", 
           "tileGroup"  : ["Italian", "Matt", "Rought"], 
           "tileDetails" : 
            { 
             "tileSize"   : "60x60", 
             "tileType"   : "Polished" 
            } 
          } 
         ] 
        }; 


$scope.tileGroupFilter = function(elm) { 
    return (elem.tileGroup.indexOf("Polished") > 0) ; 
} 
+0

什麼是挑選:在過濾器?以及它的工作如何?對於這裏仍然是新的角度 –

相關問題