在纸元素下拉列表中检索所选项目
Retrieving the selected item in a paper-element dropdown
我有以下代码遵循 https://github.com/dart-lang/polymer-core-and-paper-examples/blob/master/web/paper_dropdown.html and https://github.com/dart-lang/polymer-core-and-paper-examples/blob/master/web/paper_dropdown.dart
中的示例
已编辑
.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 代码在下拉列表(正常显示)中检索所选元素?
更新
我认为这是最简单的方法
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);
}
旧
paper-dropdown
中没有selected
。在提供 selected
.
的 paper-dropdown
中包裹一个 core-menu
见
- https://www.polymer-project.org/0.5/docs/elements/core-menu.html and the example at https://www.polymer-project.org/0.5/docs/elements/paper-dropdown-menu.html
简单使国家/地区列表可见
final List<Country> cuntries = toObservable[
const Country('Afghanistan', 'AF'),
const Country('Åland Islands', 'AX')}]
检索到选择。
我的疏忽。
我有以下代码遵循 https://github.com/dart-lang/polymer-core-and-paper-examples/blob/master/web/paper_dropdown.html and https://github.com/dart-lang/polymer-core-and-paper-examples/blob/master/web/paper_dropdown.dart
中的示例已编辑
.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 代码在下拉列表(正常显示)中检索所选元素?
更新
我认为这是最简单的方法
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);
}
旧
paper-dropdown
中没有selected
。在提供 selected
.
paper-dropdown
中包裹一个 core-menu
见
- https://www.polymer-project.org/0.5/docs/elements/core-menu.html and the example at https://www.polymer-project.org/0.5/docs/elements/paper-dropdown-menu.html
简单使国家/地区列表可见
final List<Country> cuntries = toObservable[
const Country('Afghanistan', 'AF'),
const Country('Åland Islands', 'AX')}]
检索到选择。
我的疏忽。