1

I have a firebase element that is pulling in the last 5 items

<firebase-element id="base" location="https://mydb.firebaseio.com/mydata" data="{{items}}" keys="{{keys}}" limit="5" ></firebase-element>

That is bound to this repeat region

<template repeat="{{id in keys}}">

<x-chat-list id="chatList"  username="{{items[id]['uuid']}}" text="{{items[id]['text']}}" ></x-chat-list>

</template>

I simply need to reverse the order of the repeat region.

Matt2012
  • 130
  • 1
  • 8

2 Answers2

0

I think you just need to observe the array and reverse it (or store the reversed values in another attribute) Ex : keysChanged : function() { this.keys.reverse(); }

If the firebase-element sometimes changed the values in the array without triggering the keysChanged function, you can also use the observe object

BLASTOR
  • 316
  • 1
  • 6
0

Just add a custom Polymer expression, e.g.:

PolymerExpressions.prototype.revArray = function(a) {
 return a.reverse();
}

and pipe your data to it:

<template repeat="{{id in keys | revArray}}">

Now you can use this anywhere since the expression handler is global.

flyandi
  • 1,919
  • 16
  • 25