Remove duplicates from finsweet list nest


I am using finsweet list nest to populate links like (tags). which works as required my problem is that then there are duplicates. To get around this I tried using custom code:

<script>
var seen = {};
$('a').each(function() {
    var txt = $(this).text();
    if (seen[txt])
        $(this).remove();
    else
        seen[txt] = true;
});
</script>

which results in showing duplicate as combination within each collection list. and i want it to resolve duplicates across all items no matter what collection list they are in.

Full list before running custom code:

After running custom code:

I have run the code outside webflow and works as in tended.

Much appreciate any ideas :slight_smile:

1 Like

@Richard_Atkinson , If you’ve implemented this in Webflow, could you please share the read-only link?

1 Like

Thanks…. but I have solved this now it needed the finsweet callback, but as the attributes v2 is more recent release i couldn’t find any example how to implement this. I was trying with attributes v1 without knowing - The solution for attributes v2 below if anybody has the same issue :slight_smile:

1 Like

Yep, the Finsweet fs-attributes v2 needs the onLoad callback to ensure deduping runs after the DOM updates. Had the same issue on a tag system for a client. This worked:

window.fsAttributes = window.fsAttributes || [];
window.fsAttributes.push([
  'nest',
  (listInstances) => {
    var seen = {};
    $('a').each(function () {
      var txt = $(this).text();
      if (seen[txt]) $(this).remove();
      else seen[txt] = true;
    });
  },
]);

1 Like