聚合物dom-bind与dom-repeat不起作用

时间:2015-09-23 04:36:38

标签: polymer-1.0

以下html文件未按预期显示结果。

我不知道这是什么问题。

<!DOCTYPE html>
<html>
<head>
    <title>auto-binding test</title>
    <script src="bower_components/webcomponentsjs/webcomponents.js"></script>
    <link rel="import" href="bower_components/polymer/polymer.html"/>

</head>
<body unresolved>
<template id="greeter" is="dom-bind">
    <template is="dom-repeat" items="{{names}}">
        <p>Hello, {{item}}, how are you today?</p>
    </template>
</template>
<script>
    (function(){
        document.querySelector('#greeter').names = ["Alice", "Brenda"];
    })()
</script>

</body>
</html>

1 个答案:

答案 0 :(得分:1)

  

要绑定到子元素的textContent,您只需在子元素中包含注释即可。绑定注释当前必须跨越标记的整个内容:

<template>   
  First: <span>{{firstName}}</span><br>
  Last: <span>{{lastName}}</span>
</template>

所以改为:

<p>Hello, <span>[[item]]</span>, how are you today?</p>