dart - Best way to get model associated with a core-item element? -
dart - Best way to get model associated with a core-item element? -
consider polymer fragment:
class="lang-html prettyprint-override"><core-menu on-core-activate="{{selectuser}}"> <template repeat="{{user in users}}"> <core-item label="{{user.name}}"></core-item> </template> </core-menu>
when user clicks on core-item
element , triggers selectuser
, how determine user associated activated core-item
? i'd instance actual object, , not stringified identifier utilize object.
polymer >= 1.0.0
@reflectable void someclickhandler(dom.event event, [_]) { // native events (like on-click) var model = new domrepeatmodel.fromevent(event); // or custom events (like on-tap, works native events) var model = new domrepeatmodel.fromevent(converttojs(event)); var value = model.jselement['items']; // or var value = model.jselement[$['mylist'].attributes['as']]; // if used `as="somename"` // in <core-list> or <template is="dom-repeat"> }
there open issue related custom events: https://github.com/dart-lang/polymer-dart/issues/624
polymer <= 0.16.0
in click handler
class="lang-dart prettyprint-override">import 'package:template_binding/template_binding.dart' tb; ... void onclick(mouseevent e) { tb.templateinstance ti = tb.nodebind(e.target).templateinstance; var value = ti.model.value inner; }
see in polymer.js children of template have reference template, how can done in polymer.dart more details.
dart dart-polymer
Comments
Post a Comment