当property的值等于itemSearch时如何获取组对象

时间:2016-04-06 05:11:27

标签: javascript angularjs json underscore.js lodash

当[array]值为一个属性为itemSearch时,如何获取group {object}, 即时通讯使用_.lodash / underscore

{
"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"
        }
}
] 
}

如何使用tileGroup中的过滤器获取对象tileName:Fama Brown和Fama Nero,值为"抛光"?

由于该组具有Polished的唯一值。

1 个答案:

答案 0 :(得分:0)

您可以使用http://forum.highcharts.com/highcharts-usage/synchronize-chart-with-shared-tooltip-t33919/代替lodash,这是非常直接的实现, 如果您使用ng-repeat,请尝试以下,

<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) ;
}