如何使用核心菜单选择

时间:2014-08-15 23:36:40

标签: dart dart-polymer core-elements

我从http://www.dartdocs.org/documentation/core_elements/0.1.0+1/index.html#core_elements/core_elements-core_menu.CoreMenu

获取以下内容
  <section>
    <core-menu selected="0" on-core-select="{{selectAction}}">
      <core-item icon="settings" label="Settings"></core-item>
      <core-item icon="dialog" label="Dialog"></core-item>
      <core-item icon="search" label="Search"></core-item>
    </core-menu>
  </section>


  void selectAction (e, detail)
  {
    if ( e.target.isSelected)
    {
      var selectedItem = detail.item;

      print ( selectedItem );
    }
  }

即使只是尝试使用代码运行应用程序而不尝试选择,也会出现以下内容

Exception: Class 'CoreMenu' has no instance getter 'isSelected'.

NoSuchMethodError: method not found: 'isSelected'
Receiver: Instance of 'CoreMenu'

这里有错误或代码是错误的

1 个答案:

答案 0 :(得分:0)

来自我的应用程序的示例

import 'dart:js' as js;

  void menuSelectHandler(dom.CustomEvent e) {
    var detail = new js.JsObject.fromBrowserObject(e)['detail'];
    //var detail = e['detail']; // you can try without js.JsObject.fromBrowserObject(e), but the last time I tried it didn't work for me without it

    if(detail['isSelected']) {
      var item = (detail['item'] as CoreItem);
      selectedMenuLabel = item.label;

    }
  }