web component - Polymer 1.0: Using template dom-repeat inside paper-menu elements to display iron-pages on selection -
using polymer 1.0, have created paper-drawer-panel layout. in drawer have menu using paper-menu paper-items bound iron-pages. took example content switcheroo core-pages -- polycasts #09 , converted use polymer 1.0 elements. in code below can see commented section in paper-items hard-coded. works fine.
my next step try , build menu dynamically using <template is="dom-repeat">
element iterate on arbitrary array of menu items. menu rendered correctly (i can see menu items bound array), cannot click on items , no iron-pages displayed. seems data-category attribute used attr-for-selected not working inside <template is="dom-repeat">
.
in ways can work? edit: removing attr-for-selected attributes , switching iron-pages using index work, relying on index of array not option in situation.
my index.html follows:
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"> <meta name="mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-capable" content="yes"> <title>my test</title> <script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"></script> <link rel="import" href="bower_components/polymer/polymer.html"> <link rel="import" href="bower_components/iron-icons/iron-icons.html"> <link rel="import" href="bower_components/iron-pages/iron-pages.html"> <link rel="import" href="bower_components/paper-drawer-panel/paper-drawer-panel.html"> <link rel="import" href="bower_components/paper-toolbar/paper-toolbar.html"> <link rel="import" href="bower_components/paper-header-panel/paper-header-panel.html"> <link rel="import" href="bower_components/paper-icon-button/paper-icon-button.html"> <link rel="import" href="bower_components/paper-item/paper-item.html"> <link rel="import" href="bower_components/paper-styles/paper-styles.html"> <link rel="import" href="bower_components/paper-menu/paper-menu.html"> <style> </style> </head> <body> <my-app></my-app> <dom-module id="my-app"> <style> </style> <template> <paper-drawer-panel> <paper-header-panel drawer class="fit"> <paper-toolbar> <div>drawer</div> </paper-toolbar> <paper-menu class="content fit" selected="{{page}}" attr-for-selected="data-category"> <!-- works --> <!-- <paper-item data-category="item1" label="item1"> <span>john smith</span> </paper-item> <paper-item data-category="item2" label="item2"> <span>jane doe</span> </paper-item> --> <!-- not work --> <template is="dom-repeat" items="{{names}}"> <paper-item data-category="{{item.itemnum}}" label="{{item.itemnum}}"> <span>{{item.first}}</span><span>{{item.last}}</span><span>{{item.itemnum}}</span> </paper-item> </template> </paper-menu> </paper-header-panel> <paper-header-panel main class="fit"> <paper-toolbar> <paper-icon-button icon="menu" paper-drawer-toggle></paper-icon-button> <div class="flex">main content</div> </paper-toolbar> <iron-pages selected="{{page}}" attr-for-selected="data-category"> <section data-category="item1"> <h1>item 1</h1> <div>item 1 content...</div> </section> <section data-category="item2"> <h1>item 2</h1> <div>item 2 content...</div> </section> </iron-pages> </paper-header-panel> </paper-drawer-panel> </template> <script> polymer({ is: "my-app", ready: function() { this.names = [{itemnum: "item1", first: "john", last: "smith"}, {itemnum: "item2", first: "jane", last: "doe"}]; } }); </script> </dom-module> </body> </html>
try <paper-item data-category$="{{item.itemnum}}" label$="{{item.itemnum}}">
, docs, call paper-item.setattribute('data-category', itemnum) instead of paper-item.data-category = itemnum.
https://www.polymer-project.org/1.0/docs/devguide/data-binding.html#attribute-binding
Comments
Post a Comment