0

我有一个简单的 Polymer 元素,我在dom-repeat模板中使用它。

<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>

如何访问名称值以便将其从flowDictionnary字典中删除?我尝试使用 JQuery 来做到这一点,但我不知道如何在 Polymer({...}) 函数中插入 Jquery 代码。是的,我是网络开发新手。

4

1 回答 1

0

这应该有效。

<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>
于 2016-01-12T22:29:26.420 回答