如果 id 有破折号,如何访问本地 DOM 中的元素?
How to access element in a local DOM if id has dash?
<dom-module id="name-tag">
<template>
<div id="offices-list"></div>
</template>
<script>
Polymer({
is: "name-tag",
ready: function() {
var div_new = document.createElement('div');
Polymer.dom(this.$.officesList).appendChild(div_new);
}
});
</script>
</dom-module>
当前出现错误:
Uncaught HierarchyRequestError: Failed to execute 'appendChild' on
'Node': Only one element on document allowed.
但是,如果我将 id 从 "offices-list" 更改为 "officesList",它会起作用。我怎样才能做同样的事情来保持 ID 不变,即使用破折号?
这是一个开放的 issue/enhancement 聚合物:
https://github.com/Polymer/polymer/issues/1747 also https://github.com/Polymer/polymer/issues/150
解决方法是使用 this.$['offices-list']
<dom-module id="name-tag">
<template>
<div id="offices-list"></div>
</template>
<script>
Polymer({
is: "name-tag",
ready: function() {
var div_new = document.createElement('div');
Polymer.dom(this.$.officesList).appendChild(div_new);
}
});
</script>
</dom-module>
当前出现错误:
Uncaught HierarchyRequestError: Failed to execute 'appendChild' on 'Node': Only one element on document allowed.
但是,如果我将 id 从 "offices-list" 更改为 "officesList",它会起作用。我怎样才能做同样的事情来保持 ID 不变,即使用破折号?
这是一个开放的 issue/enhancement 聚合物:
https://github.com/Polymer/polymer/issues/1747 also https://github.com/Polymer/polymer/issues/150
解决方法是使用 this.$['offices-list']