在身体

时间:2017-02-17 09:20:13

标签: javascript polymer

我尝试在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>

1 个答案:

答案 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:我点击了点按即可点击以允许点击并触摸您的链接。