我尝试在html文件中包含2个元素,如下所示:
<html>
<body>
<iron-ajax id="requestContent"></iron-ajax>
<my-custom-element></my-custom-element>
</body>
</html>在my-custom-element,我有一个带有on-click属性的链接标签,当我单击iron-ajax上的链接时,我想通过id选择my-custom-element元素。我该怎么做呢?
<dom-module id="my-custom-element">
<template>
<a href$="/target-page" on-click="_aFunction">click me</a>
</template>
<script>
Polymenr({
is: 'my-custom-element',
_aFunction: function(){
console.log(this.parentNode); // output element body
console.log(this.parentNode.$); // undefined
// console.log(this.parentNode.$.requestContent);
}
});
</script>
</dom-module>发布于 2017-02-17 21:40:29
子对象触发一个带有要选择的id的自定义事件,父对象触发一个选择id的函数。
父级
<iron-ajax id="requestContent" on-select-ajax="handleSelection"></iron-ajax>
handleSelection: function(e) {
// do what you have to do with e.name
// you can pass the data anywhere
}孩子
<dom-module id="my-custom-element">
<template>
<a href$="/target-page" on-tap="_aFunction">click me</a>
</template>
<script>
Polymenr({
is: 'my-custom-element',
_aFunction: function(e, detail) {
this.fire('select-ajax', {name: requestContent});
}
});
</script>
</dom-module>ps:我把on-click改为on-tap,这样就可以点击和触摸你的链接了。
https://stackoverflow.com/questions/42293975
复制相似问题