Dart 在“图纸元素”下拉列表中检索选定项目
我在和的示例后面有以下代码 已编辑 .htmlDart 在“图纸元素”下拉列表中检索选定项目,dart,dart-polymer,paper-elements,Dart,Dart Polymer,Paper Elements,我在和的示例后面有以下代码 已编辑 .html <paper-dropdown-menu label='Click to select..' on-core-select='{{onCoreSelectCountryHandler}}'> <paper-dropdown class='dropdown'> <core-menu id='country' class='menu'> <template repeat='{
<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>
{{country.name}
.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;
}
最终列表国家=[
const Country(‘阿富汗’、‘AF’),
const Country(‘奥兰群岛’、‘AX’)];
阶级国家{
最后的字符串名;
最终字符串代码;
const Country(this.name,this.code);
}
void oncreselectCountryHandler(dom.CustomEvent e,变量详细信息){
var detail=newjsobject.fromBrowserObject(e)['detail'];
如果(详细信息['isSelected']){
//不工作-如何获取下面尝试的选择
//详细信息应与国家/地区类别相关,但
//我似乎无法把它联系起来,这样我就可以得到选择。
var kuntry=(详细信息['item']作为PaperItem)。文本;
}
如何使用dart代码在下拉列表(正常显示)中检索所选元素?更新 我认为这是最简单的方法
void oncreselectCountryHandler(dom.CustomEvent e,var detail){
打印(国家[$['country'].选中].name);
//或者如果您确实需要访问``元素
打印(详细信息['item'].text);
}
旧的
在纸张下拉列表中没有选择的
。在纸张下拉列表中包装一个核心菜单
,该下拉列表提供了选择的
见
-而在Simple中的示例使国家列表变得可见
final List<Country> cuntries = toObservable[
const Country('Afghanistan', 'AF'),
const Country('Åland Islands', 'AX')}]
final List cuntries=Toobbservable[
const Country(‘阿富汗’、‘AF’),
const Country(‘奥兰群岛’、‘AX’)}]
将检索所选内容
我的疏忽。没问题,只是为了保持Dart区域的良好维护:)这就是我对代码所做的所有更改,以使其正常工作。您的答案打印(详细信息['item'].text);证实了这一点。如果我删除toObservable,它仍然不会打印项目。毕竟,我问这个问题是因为我的代码不起作用。我明白了。我无法想象这有什么关系。也许您在应用程序中使用的方式有所不同。例如,当您从服务器加载国家/地区或在加载应用程序后以任何其他方式修改列表内容时,您肯定需要toObservable