简体   繁体   English

聚合物纸标签选择无法正常工作

[英]Polymer paper-tabs selection not working as expected

While developing my personal website with Polymer (v1.0+), by modifying a copy of the PSK (Polymer Starter Kit), I'm running into problems with my selected attribute when trying to make use of Polymer's dom-repeat templates for my navigation menus with an array of my routes and their attributes. 在使用Polymer(v1.0 +)开发个人网站时,通过修改PSK(Polymer Starter Kit)的副本,当尝试为我的用户使用Polymer的dom-repeat模板时,我selected属性出现了问题包含我的路线及其属性的数组的导航菜单。

The repeating behavior works, the routing works, and (most of) the data works as expected, but the selection is not recognized and/or displayed correctly, translating into the selected menu item not being visually "selected" (not having the fancy selection effects). 重复的行为起作用,路由起作用,并且(大多数)数据按预期起作用,但是该选择未被正确识别和/或显示,从而转换为未被视觉“选中”的所选菜单项(没有精美的选择)效果)。

Although I understand a bit of HTML, CSS, and JS, I'm still quite new to web-development, so this is probably some understanding about data-binding or JS that I'm still missing. 尽管我了解一些HTML,CSS和JS,但是我对Web开发还是很陌生,所以这可能是我仍然缺少的关于数据绑定或JS的一些知识。

So here are the questions: 所以这是问题:
Why does the dynamic version of the code not work? 为什么动态版本的代码不起作用? And how can I fix it? 我该如何解决?


Here is what I have: 这是我所拥有的:

app.js: app.js:

(function (document) {
  'use strict';

  var app = document.querySelector('#app');

  app.baseUrl = '/';

  /*
   * About 100 lines of unrelated "...", about 60 taken from PSK
   */

  app.routeMap = [
    {name: "home", text: "Home", icon: "home", url: app.baseUrl},
    {name: "about", text: "About", icon: "face", url: app.baseUrl + "about"},
    {name: "users", text: "Users", icon: "info", url: app.baseUrl + "users"},
    {name: "contact", text: "Contact", icon: "mail", url: app.baseUrl + "contact"}
  ];

})(document);

HTML that works: 有效的HTML:

<template is="dom-bind" id="app">

  <!-- ... -->

  <paper-tabs attr-for-selected="data-route" selected="[[route]]">
    <paper-tab data-route="home">
      <a href="{{baseUrl}}">
        <iron-icon icon="home"></iron-icon>
        <span>Home</span>
      </a>
    </paper-tab>
    <paper-tab data-route="about">
      <a href="{{baseUrl}}about">
        <iron-icon icon="face"></iron-icon>
        <span>About</span>
      </a>
    </paper-tab>
  </paper-tabs>
</template>

HTML that doesn't work: (but that I'm trying to make work) 无法使用的HTML :( 但我正在尝试使之工作)

<template is="dom-bind" id="app">

  <!-- ... -->

  <paper-tabs attr-for-selected="data-route" selected="[[route]]">
    <template is="dom-repeat" items="{{routeMap}}">
      <paper-tab data-route="{{item.name}}">
        <a href="{{item.url}}">
          <iron-icon icon="{{item.icon}}"></iron-icon>
          <span>{{item.text}}</span>
        </a>
      </paper-tab>
    </template>
  </paper-tabs>
</template>

聚合物绑定到元素属性需要这样的记录data-route$=name of route

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM