我编写了一个简单的 Polymer 自定义元素,并希望使用其中的 paper-button
元素。我的代码如下所示:
<link rel="import" href="bower_components/Polymer/polymer.html">
<link rel="import" href="bower_components/paper-button/paper-button.html">
<dom-module id='chart-label'>
<template is="dom-bind">
<template is="dom-repeat" items="{{lables}}">
<input type=checkbox checked="true" id="checkb" value={{item}} name="check" on-change="checkChanged"><b>{{item}}</b>
</template>
</template>
<script>
Polymer({
is: 'chart-label',
buttonStates: [],
properties: {
buttonstates: {
type: Array,
value: [],
notify: true,
},
lables:Array
},
ready: function () {
for (var i = 0; i < this.lables.length; i++) {
this.buttonstates.push(true);
}
},
checkChanged: function (e) {
var it = e.model.item;
var index = this.lables.indexOf(it);
console.log(index + " index checked");
if (e.target.checked) {
this.buttonstates[index] = true;
} else {
this.buttonstates[index] = false;
}
// for (var i = 0; i < this.lables.length; i++) {
// alert(this.buttonstates[i]);
// }
//console.log("this.buttonstates"+this.buttonstates);
this.fire('checked',this.buttonstates);
}
});
</script>
</dom-module>
当我尝试测试此代码时,它失败并出现以下错误:
Uncaught NotSupportedError: Failed to execute 'registerElement' on 'Document': Registration failed for type 'dom-module'. A type with that name is already registered.
我在这里缺少什么?
注意我正在 Polymer 1.0 上编写此代码 **
最佳答案
我搞乱了代码中的聚合物版本。我在构建新应用程序后修复了它。
关于javascript - 在聚合物 1.0 中,在自定义元素中导入聚合物按钮会出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31717363/