Polymer repeat pattern "refresh"

Need help with concept. Creating a custom item that displays data from my database. Using a repeat pattern, it works great. The report is grouped and therefore each row in the report contains a different level of data that is displayed after you collapse into a row. So now I want to โ€œupdateโ€ the report data to reflect changes in sorting or grouping. The report is based on an โ€œindexingโ€ array that points to actual data. I sort / group data in an index array and use this array as an array to repeat the pattern.

<div id="rptbody"> <template repeat="{{group in groups}}"> <pmg-group groupid={{group.id}} groupval={{group.groupval}} groupobj={{group.groupobj}}></pmg-group> </template> </div> 

So, in this example, an array of groups is a list of keys for my data. In this example, the array of groups is ordered correctly, so [0] contains the first index of the data array, and [length-1] contains the last. I have a sort that changes the index value in groups, but does not add or remove elements from the array of groups.

So my question after my resort is how to get the template to re-view the list of groups. I found that I can set groups = [] and then reload groups (groups.push ({idx}) from my main index, and it will update the template, however it seems wasteful to me.

Is there a way to initiate a template update or re-scan of an array of groups and reorganization of the DOM based on value changes? Do I think this?

Thoughts?

Dan

+6
source share
2 answers

In the past, I got template repeat for updating as follows:

 var template = document.querySelector('template'); // Use specific selector here template.iterator_.updateIteratedValue(); // Force Polymer to refresh template 

It's a hack, but it looks like it is still working. Here is jsbin .

+2
source

Just stumbled upon this and found out that we should use the .set method of the data model of the Polymer element. Could not find any documents about this, but it seems interesting https://www.polymer-project.org/1.0/docs/devguide/data-binding.html#set-path . Avoid these hackers because they can change the API in time.

+1
source

Source: https://habr.com/ru/post/972407/


All Articles