2

使用旧的 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
4

1 回答 1

0

Jacek,这对我有用。在我的一个应用程序中,我对条件渲染进行了以下使用(更改了变量名称以匹配您的示例):

 <template bind if="{{view == 'dashboard'}}">
   <p>{{view}}</p>
 </template>

在此代码段中,{{view}} 仅在 score 等于 4 时呈现:

<template bind if="{{score == 4}}">
  <h2>Score: {{score}}</h2>
</template>

即使您更改bind if为 just ,条件句也有效if

您可以发布更多代码吗?也许问题出在其他地方。

于 2013-09-18T15:03:56.270 回答