Is there a Polymer dom api method or other ways to automatically update the repeated template with additional elements, should the underlying array gets updated?
I have a dynamic array that gets updated through ajax calls repeatedly. This array keeps changing its length (elements get incrementally appended or removed based on the ajax response). The array is reflected in the document through <template is="dom-repeat">
. Is there a way to automatically update the dom when the underlying array gets updated?
At present, the only ways I can see are
By using 2, I will not be able to use the transition effects of the list automatically updating in the view. I want to be able to use these effects.
The <dom-repeat> element will automatically stamp and binds one instance of template content to each object in a user-provided array. dom-repeat accepts an items property, and one instance of the template is stamped for each item into the DOM at the location of the dom-repeat element.
Conditional templates introduce some overhead, so they shouldn't be used for small UI elements that could be easily shown and hidden using CSS. Instead, use conditional templates to improve loading time or reduce your page's memory footprint.
Element <dom-if> (DomIf) Custom element that conditionally stamps and hides or removes template content based on a boolean flag.
If you update the array with this.push('myarray', {item});
then that will trigger Polymer's binding observers. More info is in the documentation at https://www.polymer-project.org/1.0/docs/devguide/properties#array-mutation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With