Polymer: dom-repeat items - Is it possible to shuffle repeating items?

98 Views Asked by At

In Polymer template: dom-repeat items - Is it possible to shuffle repeating items?

1

There are 1 best solutions below

0
JoelCode On

Yes, use a sort function that will randomly assign the item position rather than actually sorting it.

  <template is="dom-repeat" items="[[items]]" sort="_sortItems" initial-count="1">
    <a href$="#[[section]]/[[item.id]]" class="item" aria-label$="More information about [[item.title]]">
      <shrine-item item="[[item]]"></shrine-item>
    </a>
  </template>

_sortItems: function() {
  return Math.round(Math.random()*3) - 1;
}