How get the value of this Polymer element?

﹥>﹥吖頭↗ 提交于 2019-12-12 03:09:36

问题


I have a simple Polymer element, that I use in a dom-repeat template.

<link rel="import" href="../../bower_components/polymer/polymer.html">
<dom-module id="flow-element" attributes="name kind">
<template>
  <paper-material class="flow" elevation="1">
      <span>
        //delete button
        <paper-button class="delete" on-click="handleClick({{name}})">
          <iron-icon  icon="delete" ></iron-icon>
        </paper-button>
      </span>
    <paper-item id="name">{{name}}</paper-item>
    <paper-item id="kind">{{kind}}</paper-item>
  </paper-material>
  <!-- data bindings in local DOM -->
</template>

<script>
Polymer({
  is: 'flow-element',
  handleClick: function(name) {
    console.log('clicked: ');
    // remove the item 
    delete flowListID.flowDictionnary[name];
  }
});
</script>
</dom-module>

How can I access the name value so I can remove it from the flowDictionnary dictionary ? I tried to do it using JQuery but I don't know how insert the Jquery code inside the Polymer({...}) function. And yes, I'm new to web dev.


回答1:


This should work.

<link rel="import" href="../../bower_components/polymer/polymer.html">
<dom-module id="flow-element">
<template>
  <paper-material class="flow" elevation="1">
      <span>
        //delete button
        <paper-button class="delete" on-click="handleClick">
          <iron-icon  icon="delete" ></iron-icon>
        </paper-button>
      </span>
    <paper-item id="name">{{name}}</paper-item>
    <paper-item id="kind">{{kind}}</paper-item>
  </paper-material>
  <!-- data bindings in local DOM -->
</template>

<script>
Polymer({
  is: 'flow-element',
  properties:{name:{type:String},kind:{type:String}}
  handleClick: function() {
    console.log('clicked: '+this.name);
    //if flowListID is a global variable declared outside of your element
    // you can access it anywhere
    // in other case you can pass this variable to this element and refeer   
    //  it using this. As follows: delete this.flowListID.flowDictionnary[name]; 
    // remove the item 
    //delete flowListID.flowDictionnary[name];
  }
});
</script>
</dom-module>


来源:https://stackoverflow.com/questions/34754236/how-get-the-value-of-this-polymer-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!