在飞镖聚合物1.0中使用铁名单。尝试通过选择列表中的项目来实现铁列表。这适用于项目是字符串时,但对结构化类型失败。聚合物1.0 - 铁名单 - 选择
运行下面的代码后,打印输出得到。
>Contains : false
>Uncaught Unhandled exception:
>NoSuchMethodError: method not found: 'shorttext'
>Receiver: Instance of 'JsObjectImpl'
断点内(objText!= NULL)清单 “objText-> JavaScriptView->原>获取/设置shorttext” 关闭,但提示一些错误的结合。
铁列表文件提到了关于对该项目采取行动的内容。文档中的JavaScript示例有选择并使用模型。
为真时,轻敲行将选择项目,将其数据模型的设定通过选择属性检索选择的项目。
请注意,点击列表项中的可聚焦元素不会导致选择,因为它们被假定为有自己的操作。
好的,任何人都进入了飞镖聚合物1.0的相似部分?也只是建议如何处理选择的铁名单是值得欢迎的?
HTML端:
<iron-list id="id_list" items="{{listitem}}" as="item" selection-enabled>
<template>
<paper-item on-tap="tap_event">{{item.shorttext}}</paper-item>
</template>
</iron-list>
在飞镖侧:
class ItemText extends JsProxy {
@reflectable
String shorttext;
ItemText(this.shorttext);
}
@PolymerRegister('list-demo')
class ListDemo extends PolymerElement {
@property
List<ItemText> listitem;
@property
int nrelements = 10;
// Constructor used to create instance of MainApp.
ListDemo.created() : super.created(){
List<ItemText> l = [];
for (int i = 0; i < nrelements; ++i){
l.add(new ItemText('Name ' + i.toString()));
}
listitem = l;
print('created : ${$['id_list'].selectionEnabled}');
this.notifyPath('listitem', listitem);
}
@reflectable
void tap_event(event, [_]) {
IronList e = $['id_list'];
Object objText = e.selectedItem;
if (objText != null){
print('Contains : ${listitem.contains(objText)}');
print('The short text : ${objText.shorttext}');
}
}
}
谢谢,对于响应速度非常快。建议的解决方案有效。 'convertToDart(e.selectedItem);'使逻辑有效。当然,在selectedItem和@Observe方法上绑定的解决方案更好,这里newValue指向列表中正确的项目,并且不需要任何转换。我可以将原始问题报告为一个错误,或者至少有更多关于此的文档。你有什么建议? –
我会报告错误并让Polymer小组决定如何继续。如果这回答您的问题,请将其标记为已答复,并在upvote按钮下面的复选标记处,谢谢! –
你有一点。我会报告它,也在iron_list.dart中获取selectedItem,所以对我来说它应该返回一个明确定义的dart对象。 –