通过更改底层数组来动态更新dom-repeat模板 [英] Dynamic update of dom-repeat templates by changing the underlying array

查看:147
本文介绍了通过更改底层数组来动态更新dom-repeat模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个聚合物dom api方法或其他方法来自动更新重复的模板与附加元素,底层数组是否更新?

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?

我有一个动态数组,通过重复的ajax调用更新。这个数组不断改变它的长度(元素根据ajax响应递增地附加或删除)。该数组通过< template is =dom-repeat> 反映在文档中。当底层数组更新时,有没有办法自动更新dom?

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


  1. 识别增量更新并手动附加或删除节点。

  2. 删除整个重复模板容器并重新设置一个新模板。反正我也不知道如何动态地标记一个新的模板。这可能吗?我可以想到实现这一点的一种方法是使用另一个自定义元素来重复模板戳记,并且每当有数组更新时,删除当前元素,通过将更新的数组传递给元素来附加一个新元素。

通过使用2,我将无法使用列表中的过渡效果在视图中自动更新。我想要使​​用这些效果。

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.

推荐答案

如果用 this.push更新数组('myarray',{item}); 那么这将触发Polymer的绑定观察者。更多信息请参见 https://www.polymer- project.org/1.0/docs/devguide/properties#array-mutation

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

这篇关于通过更改底层数组来动态更新dom-repeat模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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