0
我嘗試包括2個元素的html文件的樣子:選擇鐵的Ajax元素
<html>
<body>
<iron-ajax id="requestContent"></iron-ajax>
<my-custom-element></my-custom-element>
</body>
</html>
在my-custom-element
我有一個鏈接標籤與on-click
財產,我想id
選擇iron-ajax
元素,當我點擊在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>
這可能不是一個好主意。這是因爲'my-custom-element'必須有一個擁有'iron-ajax'作爲孩子的父母。真的,你應該將一個事件發送到父元素,然後可以決定進程執行。查看[dom-bind](https://www.polymer-project.org/1.0/docs/api/dom-bind)模板和[解僱自定義事件](https://www.polymer-project .org/1.0/docs/devguide/events#custom-events) –
@BenThomas fyi,如果我把'iron-ajax'和'my-custom-element'設置爲另一個自定義元素,但是我想要在body標籤裏面的元素 – itx