【问题标题】:Binding a simple list in dart web components won't work在 dart web components 中绑定一个简单的列表不起作用
【发布时间】:2014-11-19 15:50:41
【问题描述】:
  1. 我下载了 DartEditor
  2. 我使用点击计数器示例创建了一个新的 Web 组件项目
  3. 我做了一些修改

添加自定义组件,列表选择:

import 'package:polymer/polymer.dart';

@CustomTag('list-select')
class ListSelect extends PolymerElement {

  List<String> intls = const ["enUS", "nlNL"];

  ListSelect.created() : super.created();
}

带有html

<polymer-element name="list-select">
  <template>
    <style>

    </style>
    <div>
      <select>
        <option template iterate="item in intls">{{item}}</option>
      </select>
    </div>
  </template>
  <script type="application/dart" src="list-select.dart"></script>
</polymer-element>

在 {{myappname}}.html 中,我添加了两行:

<link rel="import" href="list-select.html">

<list-select></list-select>

但是,我的选择仍然是空的。我忘记了什么?

【问题讨论】:

    标签: dart dart-polymer


    【解决方案1】:

    Polymer 中没有iterate,并且缺少{{}}

    <option template iterate="item in intls">{{item}}</option>
    

    应该是

    <template repeat="{{item in intls}}"
      <option >{{item}}</option>
    </template>
    

    有一些元素(例如 &lt;tr&gt;)不允许在某些浏览器中包含其他元素,例如 &lt;template&gt;
    支持的解决方法是添加 template repeat 属性。

    <tr template repeat="{{item in intls}}"><td>{{item}}</td></tr>
    

    但通常你对repeatif 使用&lt;template&gt; 标签。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-14
    • 2015-01-03
    • 1970-01-01
    • 1970-01-01
    • 2015-11-06
    • 1970-01-01
    • 1970-01-01
    • 2013-07-07
    相关资源
    最近更新 更多