在纸张菜单中的聚合物1.0纸张子菜单

时间:2015-12-11 16:35:27

标签: polymer polymer-1.0 paper-elements polymer-starter-kit

然后我在我的外部纸张菜单中选择一个项目,之后我导航到我的子菜单并在那里选择一个项目,仍然选择了外部项目。反过来说:

<paper-menu class="list" attr-for-selected="data-route" selected="[[route]]" selectable="a">
 <a data-route="one" href="{{baseUrl}}">
  <iron-icon icon="home"></iron-icon>
  <span>one</span>
 </a>
 <paper-submenu>
  <paper-item class="menu-trigger">two</paper-item>
  <paper-menu class="menu-content">
    <a data-route="two-1" href="{{baseUrl}}two-1">
     <paper-item>
      <iron-icon icon="home"></iron-icon>
      <span>two 1</span>
     </paper-item>
    </a>
    <a data-route="two-2" href="{{baseUrl}}two-2">
     <paper-item> 
      <iron-icon icon="info"></iron-icon>
      <span>two 2</span>
     </paper-item>
    </a>
  </paper-menu>
 </paper-submenu>
 <a data-route="users" href="{{baseUrl}}users">
  <iron-icon icon="info"></iron-icon>
  <span>Users</span>
 </a>

 <a data-route="contact" href="{{baseUrl}}contact">
  <iron-icon icon="mail"></iron-icon>
  <span>Contact</span>
 </a>
</paper-menu>

知道怎么解决吗?

2 个答案:

答案 0 :(得分:1)

这可以通过on-tap:

以编程方式管理菜单打开的属性来完成
<dom-module id="menu-nav">
    <template>
        <!-- define route for 'view', e.g. /:view -->
        <!-- define route for 'subview', e.g. /bar/:subview -->

        <paper-menu selected="{{view}}" attr-for-selected="name">
            <paper-item name="foo" on-tap="_onFoo">
                Foo
            </paper-item>

            <paper-submenu opened="{{_isSubmenu(view, _inSubmenu)}}">
                <paper-item on-tap="_onSubmenu" class="menu-trigger">
                    Bar
                </paper-item>

                <paper-menu selected="{{subview}}" attr-for-selected="subname" class="menu-content">
                    <paper-item subname="baz" on-tap="{{_onBar}}">
                        Baz
                    </paper-item>
                <paper-menu>
            </paper-submenu>
        <paper-menu>
    </template>

    <script>
        Polymer({
            is: "menu-nav",

            properties: {
                view: {
                    type: String,
                    value: "foo"
                },

                _inSubmenu: {
                    type: Boolean,
                    value: false
                }
            },

            _isSubmenu: function (view, _inSubmenu) {
                return _inSubmenu || view === 'bar';
            },

            _onFoo: function () {
                this.set('_inSubmenu', false);
                // ... transition to next route, this could depend on the router being used
                // for eample, with Excess router, this would be:
                // Excess.RouteManager.transitionTo('/foo');
            },

            _onBar: function () {
                this.set('_inSubmenu', true);
                this.set('subview', undefined);
                // ... transition to /bar/baz
            },

            _onSubmenu: function (e) {
                e.stopPropagation();
                this._onBar();
            },
        });
    </script>
</dom-module>

相关问题:https://github.com/PolymerElements/paper-menu/issues/42

答案 1 :(得分:0)

你可以这样做.. 将data-route属性添加到paper-submenu并将其与嵌套纸张菜单的selected属性绑定。

<paper-menu class="list" attr-for-selected="data-route" selected="[[route]]" selectable="a">
 <a data-route="one" href="{{baseUrl}}">
  <iron-icon icon="home"></iron-icon>
  <span>one</span>
 </a>
 <paper-submenu **data-route="[[selectedMenuItem]]"**>
  <paper-item class="menu-trigger">two</paper-item>
  <paper-menu class="menu-content" **selected="{{selectedMenuItem}}"**>
    <a data-route="two-1" href="{{baseUrl}}two-1">
     <paper-item>
      <iron-icon icon="home"></iron-icon>
      <span>two 1</span>
     </paper-item>
    </a>
    <a data-route="two-2" href="{{baseUrl}}two-2">
     <paper-item> 
      <iron-icon icon="info"></iron-icon>
      <span>two 2</span>
     </paper-item>
    </a>
  </paper-menu>
 </paper-submenu>
 <a data-route="users" href="{{baseUrl}}users">
  <iron-icon icon="info"></iron-icon>
  <span>Users</span>
 </a>

 <a data-route="contact" href="{{baseUrl}}contact">
  <iron-icon icon="mail"></iron-icon>
  <span>Contact</span>
 </a>
</paper-menu>