来自一个输入调用的多个函数 - Polymer

时间:2017-07-18 12:50:08

标签: javascript html polymer

我想知道在使用点击或输入等时,Polymer是否可以触发多个功能。

例如:

HTML (逐个列出)

<paper-input label="text please" on-input="funct1;funct2"></paper-input>

JS

funct1 : function() {
     code here to do something
},

funct2 : function() {
     code here to do something
},

或........................

HTML (将它们分组)

<paper-input label="text please" on-input="allFuncts"></paper-input>

JS

allFuncts : function() {
    funct1;
    funct2;
},

funct1 : function() {
    code here to do something
},

funct2 : function() {
    code here to do something
},

2 个答案:

答案 0 :(得分:0)

当然是简单的JS:

onclick='func1();func2()';

答案 1 :(得分:0)

我通过一些研究和询问同事找到了答案。

最好编写一个调用其他函数的函数,只记得在变量未全局定义的情况下添加this.前缀。

<强> HTML

<paper-input label="text please" on-input="allFuncts"></paper-input>

<强> JS

allFuncts : function() {
    this.funct1(); <------------------ This is where I was going wrong
    this.funct2();                     needing the "this." before the 
                                       function call
},

funct1 : function() {
    code here to do something
},

funct2 : function() {
    code here to do something
},

修改

通过玩这个,我发现你可以通过在top函数中全局声明它们(即在变量名前面没有var)将变量从top函数传递给被调用函数。但是,我认为这会导致代码内部出现不安全因素。

allFuncts : function() {
     /* var */ variableName = someVariable;

     this.funct1();
     this.funct2();
}

funct1 : function() {
     // can use **variableName** within this function
}