在纸张元素下拉列表中检索所选项目

时间:2015-04-26 03:14:14

标签: dart dart-polymer paper-elements

我在https://github.com/dart-lang/polymer-core-and-paper-examples/blob/master/web/paper_dropdown.htmlhttps://github.com/dart-lang/polymer-core-and-paper-examples/blob/master/web/paper_dropdown.dart

的示例后面有以下代码

EDITED

html的

<paper-dropdown-menu 
  label='Click to select..' 
  on-core-select='{{onCoreSelectCountryHandler}}'>
  <paper-dropdown class='dropdown'>
    <core-menu id='country' class='menu'>
      <template repeat='{{country in countries}}'>
        <paper-item>{{country.name}}</paper-item>
      </template>
    </core-menu>
  </paper-dropdown>
</paper-dropdown-menu>

.dart

final List<Country> countries = [
  const Country('Afghanistan', 'AF'),
  const Country('Åland Islands', 'AX')];

class Country {
  final String name;
  final String code;
  const Country(this.name, this.code);
}

void onCoreSelectCountryHandler(dom.CustomEvent e, var detail) {
    var detail = new JsObject.fromBrowserObject(e)['detail'];

  if (detail['isSelected']) {
  // DOES NOT WORK - HOW DO I GET THE SELECTION ATTEMPTED BELOW
  // The detail should be related to the Country class but 
   // I can't seem to relate it so I could get the selection.
  var kuntry = (detail['item'] as PaperItem).text;

}

如何使用dart代码检索下拉列表中的所选元素(正常显示)?

2 个答案:

答案 0 :(得分:1)

<强>更新

我认为这是最简单的方式

void onCoreSelectCountryHandler(dom.CustomEvent e, var detail) {
  print(countries[$['country'].selected].name);
  // or if you really need to access the `<paper-item>` element
  print(detail['item'].text);
}

<强>旧

selected中没有paper-dropdown。在提供core-menu的{​​{1}}中包裹paper-dropdown


- https://www.polymer-project.org/0.5/docs/elements/core-menu.html以及https://www.polymer-project.org/0.5/docs/elements/paper-dropdown-menu.html

的示例

答案 1 :(得分:0)

简单地使国家名单可观察

infowindow

检索选择。

我的疏忽。

相关问题