On Fri, Aug 1, 2014 at 10:42 AM, Eric Bidelman <[email protected]> wrote:
> The data binding system is smart in that it maintains a reference > <http://www.polymer-project.org/docs/polymer/databinding-advanced.html#how-data-binding-tracks-template-instances> > to the nodes it produces in the dom, based on the data model. Unless your > items physically change location in the array, they will be left intact in > the DOM. Only the minimal changes you make to the item's model will be > changed in the DOM. > > One thing you can do is maintain the origin array as the source of truth, > and setup a parallel filtered/sorted version of the array that you template > repeat over. Filter example: > > <template repeat="{{item, i in filteredList}}"> > > this.filteredListed = this.list.filter(function(item, i) { > return item.category == 'special'; > }); > > Polymer also supports inline functions/filers now, so you could do > something like this: > > <template repeat="{{l in sort(list)}}"> > > created: function() { > this.list = [6,5,4,3,2,1]; > }, > sort: function() { > this.list.sort(); > return this.list; > } > > This doesn't really work for complex values that are sorted with a comparator since the data binding system won't understand how to update them if the sort changes. ex. sort: function() { this.list.sort(function(a, b) { return a.name.localeCompare(b.name); }); return this.list; }, The binding system won't understand to resort the array when the name property changes. You'll need to fire events and reassign the array value whenever a property the sort depends on changes. Hopefully we'll get support for sort by clauses in template binding and then you could do: <template repeat="{{ user in users sort by user.name }}"> or something of that nature. - E Follow Polymer on Google+: plus.google.com/107187849809354688692 --- You received this message because you are subscribed to the Google Groups "Polymer" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/CAPJYB1hg7SxBrjc1B9JLWkxZ0%3D6PH7mmw3gPUqW32csLOfGeCA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
