我发布此内容是因为答案发布在this SO thread中不适合我。我想将额外的数据参数从纸质按钮(在 dom-repeat 中)传递到点击事件处理程序。使用以下代码片段的结果提供了没有数据的子纸张 Material 元素。
使用:
<template is="dom-repeat" items="{{someParam}}>
<paper-button on-tap="_handleTap" data-args="{{item}}">...</paper-button>
</template>
并处理:
var args = e.target.getAttribute('data-args').split(',');
或
e.target.dataset.args
两者都返回<paper-material ...>...</paper-material>
这是怎么回事?为什么目标不会返回点击的纸质按钮或其中的数据?!
最佳答案
从模板实例访问数据的最有效方法是执行以下操作:
<template is="dom-repeat" items="[[someParam]]">
<paper-button on-tap="_handleTap">...</paper-button>
</template>
...
_handleTap: function(e) {
var model = e.model.item;
// Do something
}
关于javascript - 在 Polymer 1.0 中使用纸张按钮事件无法访问数据属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32489905/