可用的旧Web UI代码:
<template instantiate="if view == 'dashboard'">
不起作用的聚合物代码:
<p>{{view}}</p> <-- this is ok, prints: dashboard
<template if="{{view == 'dashboard'}}"> <-- not work, if I change code to use bool property something like {{showDashboard}} then works ok.
正确的语法是什么?我找不到使用字符串比较实例化的任何示例。
**编辑。更多细节:
Dart SDK版本0.7.3.1_r27487
的HTML:
<p>int: {{score}}</p>
<template bind if="{{score == 4}}">
<p>ins int: {{score}}</p>
</template>
<p>String: {{view}}</p>
<template bind if="{{view == 'dashboard'}}">
<p>ins String: {{view}}</p>
</template>
<p>bool: {{showp}}</p>
<template bind if="{{showp}}">
<p>ins bool: {{showp}}</p>
</template>
镖:
class AppModel extends Object with ObservableMixin {
@observable String view = "dashboard";
@observable int score = 4;
@observable bool showp = true;
}
void main() {
query("#templ").model = new AppModel();
}
并输出:
int: 4
String: dashboard
bool: true
ins bool: true
最佳答案
Jacek,这对我有用。在我的一个应用程序中,我使用了以下条件渲染(更改了变量名以匹配您的示例):
<template bind if="{{view == 'dashboard'}}">
<p>{{view}}</p>
</template>
在此代码段中,{{view}}仅在得分等于4时才呈现:
<template bind if="{{score == 4}}">
<h2>Score: {{score}}</h2>
</template>
即使将
bind if
更改为if
,条件条件也可以工作。您可以发布更多代码吗?也许问题出在其他地方。
关于dart - Dart模板实例化从Web UI迁移到Polymer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18867939/