私はポリマーを学んでいます。子成分由来のポリマー条件クラス
- 私のタブ(親)コンポーネントに表示される条件付きクラス名を取得できません。子コンポーネントの 'selected'プロパティに応じて、 'active'クラスを
<li>
要素に追加する必要があります。 - 私は親と子のコンポーネント間のやりとりの私のやり方が最初であるとは確信していません。それは働いているが、それは右に感じることはありません...
私のindex.htmlファイル
<link rel="import" href="components/tabs.html">
<link rel="import" href="components/tab.html">
<ikb-tabs>
<ikb-tab heading="Tab #1">
<p>Content of the first tab</p>
</ikb-tab>
<ikb-tab heading="Tab #2" selected>
<p>Content of the second tab</p>
</ikb-tab>
</ikb-tabs>
マイ部品/ tabs.htmlファイル
<link rel="import" href="../../bower_components/polymer/polymer.html">
<dom-module id="ikb-tabs">
<template>
<style>
.active button {
color: red;
}
</style>
<nav>
<ul>
<template is="dom-repeat" items="{{tabs}}">
<li>
<button on-tap="openTab">{{item.heading}}</button>
</li>
</template>
</ul>
</nav>
<content></content>
</template>
<script>
Polymer({
is: 'ikb-tabs',
properties: {
activeTab: Number
},
ready: function() {
this.tabs = Polymer.dom(this).children;
},
openTab: function (e) {
Polymer.dom(this).children.forEach(function (tab, index) {
tab.selected = index === e.model.index;
});
}
});
</script>
</dom-module>
私のコンポーネント/ tab.htmlファイル
私は自分自身をそれを考え出した<link rel="import" href="../../bower_components/polymer/polymer.html">
<dom-module id="ikb-tab" attributes="heading">
<template>
<template is="dom-if" if="{{selected}}">
<div>
<content></content>
</div>
</template>
</template>
<script>
Polymer({
is: 'ikb-tab',
properties: {
heading: String,
selected: {
type: Boolean
}
}
});
</script>
</dom-module>
私は[ '鉄pages']でご覧になることをお勧めします(https://での要素.polymer-project.org/elements/iron-pages)と['paper-tabs'](https://elements.polymer-project.org/elements/paper-tabs)。 – tony19