A reliable way to access data in Polymer (inside the dom-repeat / event handler)

I need to grab data from an instance generated <template is="dom-repeat">in Polymer (v1.2.4), and I'm not sure it would be the safest way to do this, given the many available shadow DOMs available (client browser can be poly-fuzzed, etc.).

A simple example:

<template is="dom-repeat" items="[[myItems]]" id="collection"> <paper-card on-tap="handleTap"> (...)

What is the most reliable way to access model data from an event handler?

1.

handleTap: function(e) { var data = e.model.get('item.myData'); }

2.

handleTap: function(e) { var data = this.$.collection .modelForElement(Polymer.dom(e).localTarget) .get('item.myData'); }

My concern is that the simplest (# 1) option may work as expected in my environment, but may lead to errors in other browsers.

№ 2 , ( ) modelForElement.

+4
1

; , , , . , "item.myData", "item.myData" . .

. .

0

Source: https://habr.com/ru/post/1629570/


All Articles