我还有一个问题: 为什么如果我重复模板中的对象列表,模板中的元素在声明性地使用时无法看到对象?
artists = [ {name: 'whatever',..},...];
示例:
<template repeat="{{a in artists}}">
<artist-record model="{{a}}"></artist-record>
</template>
如果我强制执行同样的工作
实施例
artists.forEach(function(a) {
var node = document.createElement('artist-record');
node.model = a;
this.$.container.appendChild(node);
}, this);
有没有办法以声明的方式做到这一点?
答案 0 :(得分:0)
这对我有用:http://jsbin.com/zemawugu/1/edit
检查您的阵列分配是this.artists
而不是artists
。绑定系统需要将该数组放在模板的元素原型上才能看到它。