2016-01-12 2 views
0

J'ai un élément Polymer simple, que j'utilise dans un modèle dom-repeat.Comment obtenir la valeur de cet élément Polymer?

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

Comment puis-je accéder à la valeur du nom donc je peux l'enlever du dictionnaire flowDictionnary? J'ai essayé de le faire en utilisant JQuery mais je ne sais pas comment insérer le code Jquery dans la fonction Polymer ({...}). Et oui, je suis nouveau sur le web dev.

Répondre

0

Cela devrait fonctionner.

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

Merci, cela fonctionne parfaitement. J'ai toujours un problème avec la suppression d'un élément du dictionnaire, j'ai développé ce problème dans une autre question: http://stackoverflow.com/questions/34762372/cant-remove-element-from-dictionary – JeanRene