I am having a really hard time figuring out how to filter a scope object (row.matric && row.dimension) based on another scope object (metrics && dimension) by matching keys.
The code below is an example of the objects that i am using.
In the ng-repeat="row in rows” section; I need to only show the row.metric or row.dimention if and only if its partner metric or dimension has the key of tabled set to true.
row.metric and row.dimension are matched to metric and dimension by the key key.
For example: The row.metric ‘visits’ should be displayed, but ‘pageviews’ should not be displayed.
Here is a Plunker ( this this instead of the cod below ) the number 400 and 20 should NOT be displayed.
http://plnkr.co/edit/t15L5y40h8enPzUkkaJw?p=preview
HTML:
<table class="table">
<thead>
<tr>
<th class="dimension" ng-repeat="dimension in dimensions | filter:{tabled:true}" >{[{ dimension.name }]}</th>
<th class="metric" ng-repeat="metric in metrics | filter:{tabled:true}" >{[{ metric.name }]}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in rows">
<td class="dimension" ng-repeat="dimension in row.dimensions" >{[{ dimension.value }]}</td>
<td class="metric" ng-repeat="metric in row.metrics" >{[{ metric.current }]}</td>
</tr>
</tbody>
</table>
Objects:
metrics Example: [
{
name: 'Visits',
key: 'visits',
tabled: true
},
{
name: 'Page Views',
key: 'pageviews',
tabled: fales
}
]
dimension Example: [
{
name: 'Source',
key: 'source'
tabled: true
},
{ ... }
]
row Example: {
metrics: [
{key: 'visits', current: '203'},
{key: 'pageviews', current: '104'},
{...}
]
dimensions: [
{key: 'source', value: 'google'},
{...}
]
}
tabledforPageViewsistrueso why would it not be shown? A live demo would help, perhaps also showing expected output as wellpageviewsis supposed to be false. It is edited and fixed now. @charlietfl