Polymer-Dart 1.0 dom-如果不工作
Polymer-Dart 1.0 dom-if not working
所以我尝试使用 <template is="dom-if">
但我就是无法让它工作。
<template is="dom-repeat" items="{{row}}" as="project">
<template is="dom-if" if="{{project == null}}">
<span>Untitled project</span>
</template>
<template is="dom-if" if="{{project != null}}">
<span>{{project.name}}</span>
</template>
</template>
由于某些原因,我从未显示 Untitled project
尽管有 2 个元素是 null
。
Polymer-Dart 的开发者预览版中是否还没有这些表达式?
我不知道 Polymer-Dart,但在 Polymer 1.0 中不再支持表达式 (docs)。
您可以使用 computed bindings 来实现相同的目标。
您实际上可以只使用简单的 {{project}} 和 {{!project}} 绑定。 !
是 Polymer 1.0 中唯一允许的表达式之一。它使用 JS 伪造,因此空值将是 "false",但空值也是 list/etc。
您可能还需要在准备好的方法中显式地将值初始化为 null:
ready() { if (project == null) set('project', null); }
基本上,对于null
的初始值,我们实际上将undefined发送到js端。但是,对于未定义的值,绑定根本不会 运行,因此您需要显式分配 null
以确保 dom-ifs 将计算表达式。我们这样做是为了避免在每个元素启动时为每个 属性 发送额外的更改通知。
所以我尝试使用 <template is="dom-if">
但我就是无法让它工作。
<template is="dom-repeat" items="{{row}}" as="project">
<template is="dom-if" if="{{project == null}}">
<span>Untitled project</span>
</template>
<template is="dom-if" if="{{project != null}}">
<span>{{project.name}}</span>
</template>
</template>
由于某些原因,我从未显示 Untitled project
尽管有 2 个元素是 null
。
Polymer-Dart 的开发者预览版中是否还没有这些表达式?
我不知道 Polymer-Dart,但在 Polymer 1.0 中不再支持表达式 (docs)。
您可以使用 computed bindings 来实现相同的目标。
您实际上可以只使用简单的 {{project}} 和 {{!project}} 绑定。 !
是 Polymer 1.0 中唯一允许的表达式之一。它使用 JS 伪造,因此空值将是 "false",但空值也是 list/etc。
您可能还需要在准备好的方法中显式地将值初始化为 null:
ready() { if (project == null) set('project', null); }
基本上,对于null
的初始值,我们实际上将undefined发送到js端。但是,对于未定义的值,绑定根本不会 运行,因此您需要显式分配 null
以确保 dom-ifs 将计算表达式。我们这样做是为了避免在每个元素启动时为每个 属性 发送额外的更改通知。