有没有一种方法可以在Polymer函数中从元素属性内部的
<template>
传递参数?<script src="http://www.polymer-project.org/1.0/samples/components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="http://www.polymer-project.org/1.0/samples/components/polymer/polymer.html" />
<dom-module id="example-element">
<template>
...
<paper-button id="foo" on-tap="bar">Click</paper-button>
...
</template>
</dom-module>
<script>
(function() {
Polymer({
is: 'example-element',
properties: {...},
bar: function(arg){
// Do stuff using argument arg
}
});
})();
</script>
背景研究
我浏览了文档,但未涉及此事。它没有说明是否可以或不可以。但是当我尝试时,失败了。但也许我没有做正确。所以我需要一些帮助。
我唯一找到的东西是事件监听器,但似乎无法传递我想要传递的参数,例如 id
或 name
。
之前的尝试
我曾尝试(但失败)做过类似以下的事情:
<paper-button id="foo" on-tap="bar('foo')"> Click </paper-button>
但似乎没有任何方法有效。
事件监听器的想法行不通,因为它们限制了参数,我无法获取我需要的,比如说,id
。
on-tap="bar" data-bar="foo"
,然后在事件处理程序中使用e.srcElement.getAttribute('data-bar')
。你不能像你尝试的那样传递参数。 - Let Me Tink About It