我还有一个问题:为什么如果我重复模板中的对象列表,模板中的元素在以声明方式使用时看不到该对象?

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);

有没有办法以声明方式执行此操作?

有帮助吗?

解决方案

这对我有用: http://jsbin.com/zemawugu/1/edit

检查您的数组分配是否为 this.artists 并不是 artists. 。绑定系统需要该数组位于元素原型上,模板才能看到它。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top