Polymer 1.x: 强制添加事件监听器
Polymer 1.x: Imperatively adding event listener
我已经为我的 <iron-ajax>
调用添加了一个事件侦听器到我的自定义元素。
问题
Is there a shorter (more convenient syntax) way to imperatively (i.e., using Javascript) add the event listener in Polymer?
换句话说,Polymer 库是否包含任何语法糖?
自定义-element.html
<template>
...
<iron-ajax id="ajax" last-response="{{ajax}}"></iron-ajax>
...
<template>
<script>
...
var that = this,
t = this.$.ajax;
t.addEventListener('response', function(e) {
console.log(that.ajax);
});
...
</script>
研究
You can also add an event listener to any element in the this.$
collection using the syntax nodeId.eventName
.
但我认为这仅适用于在 Polymer 对象中使用 listeners
属性 时,如:
listeners: {
'tap': 'regularTap',
'special.tap': 'specialTap'
},
我已经为我的 <iron-ajax>
调用添加了一个事件侦听器到我的自定义元素。
问题
Is there a shorter (more convenient syntax) way to imperatively (i.e., using Javascript) add the event listener in Polymer?
换句话说,Polymer 库是否包含任何语法糖?
自定义-element.html<template>
...
<iron-ajax id="ajax" last-response="{{ajax}}"></iron-ajax>
...
<template>
<script>
...
var that = this,
t = this.$.ajax;
t.addEventListener('response', function(e) {
console.log(that.ajax);
});
...
</script>
研究
You can also add an event listener to any element in the
this.$
collection using the syntaxnodeId.eventName
.
但我认为这仅适用于在 Polymer 对象中使用 listeners
属性 时,如:
listeners: {
'tap': 'regularTap',
'special.tap': 'specialTap'
},