<code-file-set> <a href="#" tabTitle="onelink">onelink</a> <a href="#" tabTitle="twolink">twolink</a> <a href="#" tabTitle="threelink">threelink</a></code-file-set><link rel="import" href="../bower_components/polymer/polymer.html"><link rel="import" href="/bower_components/core-pages/core-pages.html"><link rel="import" href="/bower_components/paper-tabs/paper-tabs.html">
<polymer-element name="code-file-set"> <template>
<paper-tabs style="max-width:{{tabBarWidth}}px" id="tabs" selected={{selected}}> </paper-tabs>
<core-pages selected="{{selected}}"> <content id="codecontent" select="a"></content> </core-pages> </template>
<script>
Polymer('code-file-set', { domReady: function() { var codeNodes = this.$.codecontent.getDistributedNodes();
for (var i = 0; i < codeNodes.length; i++) { var name = codeNodes[i].getAttribute('tabTitle'); var tab = document.createElement('paper-tab'); tab.innerHTML = name; this.$.tabs.appendChild(tab); }
this.selected = 0; this.tabBarWidth = codeNodes.length * 250; }, });</script></polymer-element>Hi Aleem,This looks like something that could be solved quite easily with template binding, have you seen that in action yet? The docs have some good examples:I'm guessing that set of <a> tags is dynamic and coming from some external source?
If so you can use the "repeat" attribute in Polymer's template binding to help create your <paper-tab> elements more declaratively. No javascript required!
<link rel="import" href="/assets/bower_components/polymer/polymer.html"><link rel="import" href="/assets/bower_components/core-pages/core-pages.html"><link rel="import" href="/assets/bower_components/paper-tabs/paper-tabs.html">
<polymer-element name="code-file-set"> <template>
<paper-tabs style="max-width:{{tabBarWidth}}px" id="tabs" selected={{selected}}> <template repeat="{{ tab in tabNames }}"> <paper-tab>{{tab}}</paper-tab> </template> </paper-tabs>
<core-pages selected="{{selected}}"> <content id="codecontent" select="a"></content> </core-pages> </template>
<script>
Polymer('code-file-set', { domReady: function() { var codeNodes = this.$.codecontent.getDistributedNodes(); this.tabNames = [];
for (var i = 0; i < codeNodes.length; i++) { this.tabNames.push(codeNodes[i].getAttribute('tabTitle')); }
this.selected = 0; this.tabBarWidth = codeNodes.length * 250; }, });</script></polymer-element>To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/CAApOkstqnapfejU6Rsuh%3DfcuQmu3SH40MuEX2bmM-cn9MtZU%3DA%40mail.gmail.com.Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.