gpt4 book ai didi

dart - 在 paper-element 下拉列表中检索所选项目

转载 作者:行者123 更新时间:2023-12-03 03:44:39 25 4
gpt4 key购买 nike

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的示例之后,我有以下代码

编辑过

.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);
}


selected中没有 paper-dropdown。将 core-menu包装在提供 paper-dropdownselected中。

看到
- https://www.polymer-project.org/0.5/docs/elements/core-menu.htmlhttps://www.polymer-project.org/0.5/docs/elements/paper-dropdown-menu.html的示例

关于dart - 在 paper-element 下拉列表中检索所选项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29873290/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com