2017-07-18 150 views
0

我想知道是否有可能在聚合物火多重功能上點擊或輸入等多種功能 - 聚合物

例如使用時:

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

回答

0

當然,在純JS:

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

onclick/oninput普通JS標籤在聚合物中不起作用,它們被替換爲點擊和輸入。所以這對我不起作用:-( – physicsboy

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

編輯

通過玩這個,我發現,你可以從頂部功能的傳遞變量通過聲明t來調用函數在頂部函數中全局下襬(即,沒有var在變量名前面)。不過,我相信這會導致代碼中的不安全感。

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

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

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