I am working on ng-table and facing an issue where I need to prevent duplicates from getting displayed via two different ng-repeats.
The JSON
hierarchy is in this manner:
{
"PageSize": 10,
"TotalRecords": 54,
"Users": [
{
"ID": 1,
"FirstName": "John",
"LastName": "Doe",
"Projects": [
{
"Id": 1,
"Name": "Asean",
"Categories": [
{
"Id": 1,
"Name": "Category1",
"Markets": [
{
"Id": 2,
"Name": "Indonesia"
},
{
"Id": 4,
"Name": "Malaysia"
}
]
},
{
"Id": 2,
"Name": "Category2",
"Markets": [
{
"Id": 2,
"Name": "Indonesia"
},
{
"Id": 4,
"Name": "Malaysia"
},
{
"Id": 7,
"Name": "Japan"
}
]
}
]
}
]
}
]
}
And the HTML
for ng-table
is:
<table class="table" ng-table="tableParams" id="relationTable">
<tr ng-repeat="mapping in $data">
<td class="text-left" data-title="'User'">{{mapping.FirstName}}</td>
<td class="text-left" data-title="'Category'"><span ng-repeat="category in mapping.Projects[0].Categories track by $index">{{category.Name}}{{$last ? '' : ', '}}</span></td>
<td class="text-left" data-title="'Market'"><span ng-repeat="category in mapping.Projects[0].Categories track by $index"><span ng-repeat="market in category.Markets track by $index">{{market.Name}}{{$last ? '' : ', '}}</span>{{$last ? '' : ', '}}</span></td>
</tr>
</table>
From above code, I generate a table where I am facing duplicates in 'Markets' column. The table looks like:
+------+----------------------+-------------------------------------------------+
|_Name_|______Categories______|_____________________Markets_____________________|
+------+----------------------+-------------------------------------------------+
|_John_|_Category1,_Category2_|_Indonesia,_Malaysia,_Indonesia,_Malaysia,_Japan_|
+------+----------------------+-------------------------------------------------+
As you can see, here Indonesia and Malaysia are being displayed twice. Please suggest a method by which I can prevent the duplicates from being displayed in the 'Markets' column.