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;
}
Additional info in this bug: https://github.com/Polymer/docs/issues/435
On Fri, Aug 1, 2014 at 9:28 AM, <[email protected]> wrote:
> Hi!
>
> I wanna create a array sorted in increasing order, and may change value of
> some elements, or add/remove elements.
> My solution is: Use <template repeat> and add listen to on-change event,
> each time I change an element will re-sort the whole array, but I am afraid
> that this may be slow, is there any better idea? Thanks!
>
> 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/bb1a3668-6969-450c-ab4b-47c6b5016e0a%40googlegroups.com
> <https://groups.google.com/d/msgid/polymer-dev/bb1a3668-6969-450c-ab4b-47c6b5016e0a%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
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/CACGqRCCTFVgWJwL35WJ%2BNi5CRnFHpGha%2BUf%3DFP5-OtaNR7BFAQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.