0
Here is my jsBin。ポリマー1.x:customStylesプロパティ値の取得
parent-element
はchild-element
の--custom-color
プロパティの値を設定します。私はchild-element
のJSからそのプロパティの価値を得たいと思っています。
Here is the documentationしかし、私はそれをどこにどのようにこれを行うに記載され見つけることができません。
答えを実際の例(jsBin)にしてください。
<h4>http://jsbin.com/kevanicebu/edit?html,console,output</h4>
<link rel="import" href="https://rawgit.com/Polymer/polymer/master/polymer.html">
<dom-module id="parent-element">
<style>
child-element {
--custom-color: blue;
}
</style>
<template>
<child-element></child-element>
</template>
<script>
Polymer({
is: 'parent-element',
});
</script>
</dom-module>
<dom-module id="child-element">
<style>
h1 {
color: var(--custom-color, green);
}
</style>
<template>
<h1 on-tap="showColor">Click Me</h1>
<p>I want the console to log the <code>--custom-color</code> property (i.e., "blue") when the user clicks above.</p>
<p>Right now, it reads: "undefined."</p>
<p>What changes do I make to the <code>showColor()</code> method?</p>
</template>
<script>
Polymer({
is: 'child-element',
showColor: function() {
// What do I need to change in the below line of code?
console.log(this.customStyle['--custom-color']);
}
});
</script>
</dom-module>
<parent-element></parent-element>
これは、[質問](http://stackoverflow.com/questions/38317155/polymer-1とほとんど同じに聞こえるあなたが実行している時に値を取得する方法です-x-how-to-imperatively-js-get-of-a-custom-css-pro)を使用して、数時間前に尋ねた、なぜ同じ質問をもう一度聞いていますか? – tony19
@ tony19:これまでの質問で実例を要求しなかったのは私のせいです。だから私は本当に私の問題を解決しませんでしたが、その質問に対する答えは技術的に正しいものでした。この質問に含まれるjsBinを見ると、私はそれが説明されると思います。 – Mowzer