1
我想選擇由ID的元素是動態創建的選擇動態元素:聚合物1.0 - 發行由ID
<dom-module id="filter-box">
<style>
:host {
display: block;
}
</style>
<template>
<h4 id="title">{{title}}</h4>
<paper-checkbox id="test">test</paper-checkbox><br>
<template is="dom-repeat" items="{{filters}}">
<paper-checkbox id="{{item}}">{{item}}</paper-checkbox><br>
</template>
</template>
</dom-module>
<script>
(function() {
Polymer({
is: 'filter-box',
properties: {
filters: {
type: Array,
notify: true,
},
title: {
type: String
}
},
ready: function() {
this.filters = [
'Commercial',
'Enterprise'
];
},
isSelected: function(filter) {
return this.$$[filter].checked;
}
});
})();
</script>
當isSelected(「東西」)叫我得到:
"Uncaught TypeError: Cannot read property 'checked' of undefined"
我可以通過這個。$。標題選擇標題,但是我不能通過這種方式選擇動態元素或者使用這個。$$作爲建議here。
感謝您的迴應,但是。$$(...)仍然返回undefined。 – Nick
你試過這個。$$('#'+ filter).checked;'? Id選擇符以'#'開頭。 –
謝謝!我在想'#'是隱含的。 – Nick