考虑这个聚合物片段:
<core-menu on-core-activate="{{selectUser}}">
<template repeat="{{user in users}}">
<core-item label="{{user.name}}"></core-item>
</template>
</core-menu>
当用户点击core-item
元素并触发selectUser
时,如何确定哪些用户与已激活的core-item
相关联?我想获取实际对象的实例,而不是我用来查找对象的字符串标识符。
答案 0 :(得分:1)
聚合物&gt; = 1.0.0
@reflectable
void someClickHandler(dom.Event event, [_]) {
// for native events (like on-click)
var model = new DomRepeatModel.fromEvent(event);
// or for custom events (like on-tap, works also for native events)
var model = new DomRepeatModel.fromEvent(convertToJs(event));
var value = model.jsElement['items'];
// or
var value = model.jsElement[$['mylist'].attributes['as']];
// if you used the `as="somename"`
// in your <core-list> or <template is="dom-repeat">
}
有一个与自定义事件相关的未解决问题:https://github.com/dart-lang/polymer-dart/issues/624
聚合物&lt; = 0.16.0
在点击处理程序
中import 'package:template_binding/template_binding.dart' as tb;
...
void onClick(MouseEvent e) {
tb.TemplateInstance ti = tb.nodeBind(e.target).templateInstance;
var value = ti.model.value as Inner;
}