我尝试在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>
答案 0 :(得分:0)
子项触发具有要选择的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:我点击了点按即可点击以允许点击并触摸您的链接。