如何获得此聚合物元素的值? [英] How get the value of this Polymer element?

查看:81
本文介绍了如何获得此聚合物元素的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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>

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

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.

推荐答案

这应该有效.

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

这篇关于如何获得此聚合物元素的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆