私はPolymer 2.0を学ぼうとしていますが、別のShadow Domから要素を取得するという問題に悩まされています。これはポリマー1では機能したが、ポリマー2.0では機能しなかった。これを書いている正しい方法は何ですか?それはちょうど私に、targetText = Null
と伝えます。Polymer 2.0異なるShadowDomのgetElementById
ありがとうございました!
これはMWEです: ポリマーWC 1:
<dom-module id="sc-navdrawer">
<template>
<style is="custom-style">
p {
font-weight: bold;
}
.changed {
color: red;
}
</style>
<p>Some text in normal p tag</p>
<div id="test" class="htmltextcontent" inner-h-t-m-l="{{inputText}}"></div>
</template>
<script>
Polymer({
is: 'sc-navdrawer',
properties: {
inputText: {
type: String,
value: "<p>Some innerhtml text in p tags</p>"
}
}
});
</script>
</dom-module>
ポリマーWC 2:代わりにgetElementByIdをを使用しての
<dom-module id="sc-testpage">
<template>
<button onclick="{{changeColor}}">Click here to change color</button>
</template>
<script>
Polymer({
is: 'sc-testpage',
changeColor: function() {
var targetText = document.getElementById("test");
console.log(targetText);
targetText.classList.add("changed");
}
});
</script>
</dom-module>
1. https://www.html5rocks.com/en/tutorials/webcomponents/shadowdom/
が互いに関連とにかくにおけるこれら二つの要素です:彼らはshadowDomがどのように動作するかをあなたに説明しますこれらのリンクを見ていますか?彼らは子供の親の関係を持っているという意味ですか? – Niklas