聚合物重复模板“刷新". [英] polymer repeat template "refresh"

查看:78
本文介绍了聚合物重复模板“刷新".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要有关概念的帮助.构建一个自定义元素以显示我的数据库中的数据.使用重复模板,效果很好.该报告已分组,因此报告中的每一行都包含另一级数据,这些数据将在您深入一行后显示.因此,现在我希望能够刷新"报表数据以反映排序或分组更改.该报告基于指向所显示实际数据的索引"数组.我对索引数组中的数据进行排序/分组,然后将此数组用作模板重复的数组.

Need help with a concept. Building a custom element that displays data from my database. Using a repeat template and it working great. The report is grouped and so each row in the report contains another level of data that is displayed once you drill into a row. So now I want to be able to "refresh" the report data to reflect sort or grouping changes. The report is based off an "indexing" array that points to the actual data displayed. I sort/group the data in the index array, and use this array as the array for the Template Repeat.

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

因此在此示例中,groups数组是我的数据的键的列表.在此示例中,groups数组的顺序正确,因此[0]包含数据数组的第一个索引,而[length-1]包含最后一个索引.我有一个排序例程,可以更改组中的索引值,但是它不会在groups数组中添加或删除项目.

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

所以我的问题是在求助之后,如何触发模板以重新扫描组列表?我发现可以设置groups = [],然后从主索引重新加载组(groups.push({idx}),它将更新模板,但是这对我来说似乎是浪费.

So my question is after my resort, how do I trigger the template to rescan the groups list? I have found that I can set groups = [], and then reload groups ( groups.push({idx} ) from my master index, and it will update the template, however that seems kind of wasteful to me.

是否有任何方法可以触发模板刷新,或重新扫描groups数组并根据值的变化重新组织DOM?

Is there any way to trigger the template to refresh, or rescan the groups array and reorganize the DOM based on the changes in the values?

推荐答案

这是一个hack,但看起来仍然可以使用. 这是一个jsbin .

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

这篇关于聚合物重复模板“刷新".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆