![](/img/trans.png)
[英]polymer iron-ajax : How to Bind data from input element to iron-ajax's body attribute
[英]Select iron-ajax element on body
我嘗試在html文件中包含2個元素,如下所示:
<html>
<body>
<iron-ajax id="requestContent"></iron-ajax>
<my-custom-element></my-custom-element>
</body>
</html>
在my-custom-element
我有一個帶有on-click
屬性的鏈接標記,當我單擊my-custom-element
上的鏈接時,我想通過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>
子級觸發具有要選擇的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:我將“點擊”更改為“點擊”,以允許點擊並觸摸您的鏈接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.