0

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

halfer
  • 19,824
  • 17
  • 99
  • 186
Ankit Maheshwari
  • 1,620
  • 6
  • 28
  • 55

1 Answers1

0

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;
}
JoelCode
  • 326
  • 1
  • 7