Issue in polymer core-menu

188 views
Skip to first unread message

mausu...@gmail.com

unread,
Nov 18, 2014, 1:41:36 PM11/18/14
to polym...@googlegroups.com
Hello,

I am trying to use polymer core menu. Below is my code.On change of menu, i am trying log the selected menu.Though it is showing in the log selected item but it is throwing error as "Uncaught TypeError: Cannot read property 'id' of undefined " after the first selection.I am not sure where i am going wrong.Need help...

<polymer-element name="yo-menus" attributes="">
  <template>
    <link rel="stylesheet" href="yo-menus.css">
<section id="midas_menus">
 <core-ajax auto
               url="menus.json"
               response="{{menus}}"    
               handleas="json">
    </core-ajax>
<template if="{{menus}}">

<paper-menu-button>
        <paper-icon-button icon="menu" noink></paper-icon-button>
       
          <core-menu class="menu" selected="0" selectedItem="{{selectedMenu}}"  valueattr='id' on-core-select="{{mainMenu}}">
            <template repeat="{{menu in menus}}">
              <paper-item id="{{menu.name}}" label="{{menu.name}}" ></paper-item>
            </template>
          </core-menu>
       
      </paper-menu-button>
  
    </template>
  </template>
  </section>
  <script>
  Polymer('yo-menus', {
      // initialize the element's model
      ready: function() {
       
      },
 mainMenu : function(){
  console.log("New item selected: " + this.selectedMenu.id);
 }
    
    });
  </script>
</polymer-element>


Regards,
Mausumi

Yvonne Yip

unread,
Nov 18, 2014, 6:11:36 PM11/18/14
to mausu...@gmail.com, polymer-dev
core-selected is fired twice per selection change, once after the previously selected item was deselected and once after the item is selected. In the deselectione event selectedItem is null. You should look at event.details and check if this is a selection or deselection event, or check selectedItem for null.

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/f0562018-a0d9-468c-9f3b-62701e1761f7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages