【问题标题】:Polymer 1 nested dom-if within dom-repeat not updating when data changesPolymer 1 嵌套的 dom-if 在 dom-repeat 中不会在数据更改时更新
【发布时间】:2015-12-14 08:45:56
【问题描述】:

当数据发生变化时,如何在dom-repeat 的更新中制作dom-if 模板??

这里的例子http://jsbin.com/xatala/edit?html,output

在示例中,数据在 1.5 秒后发生变化,但模板内的 dom-if 不会重新评估/渲染。您可以在 console.log 中看到这一点。数据已更改,但视图未更新。

您将如何进行这项工作,其背后的原因是什么?!

【问题讨论】:

  • 看看this question。您的问题与dom-ifdom-repeat 没有直接关系,而是与Polymer 中的ArraysObjects 更新有关。
  • 谢谢@Maria,这是一个有用的指针......在我的情况下这很困难,因为我正在处理元素之外的数据......将不得不重新评估我正在做的方式。
  • this.set('myItems.1.isGood', true); 不起作用吗?这允许 Polymer 知道您正在设置特定数组项中的属性。诚然,这在所有情况下都不实用。

标签: polymer polymer-1.0


【解决方案1】:

这是一个有效的例子:http://jsbin.com/nejadibuju/edit?html,console,output

<template is="dom-if" 
  if="{{arrayItem(myItems.*, index, 'isGood')}}">
      [[item.title]] is SOOO good.
</template>

你缺少的是:

Explicit bindings to array items by index isn’t supported

Bin 中添加了一些说明。 相关链接:

Polymer, binding to array items not working

http://plnkr.co/edit/aOmw4e?p=preview

【讨论】:

  • 谢谢!这很好地解释了它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-01-15
  • 1970-01-01
  • 1970-01-01
  • 2016-01-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多