2014-05-22 2 views
1

통화 및 가격 속성으로 정의 된 요소가 있습니다. 통화 속성을 영국 파운드로 설정하면 그에 따라 가격을 계산하려고합니다. 조건이 결코 진정한 기록하지 않는 경우 난 당신이 published property *Changed watcherscurrencyChanged 같은 인수를 사용하는 경우폴리머 속성 변경 기능

currencyChanged: function (attrName, oldVal, newVal) { 

    var actualPrice = this.getAttribute("usdprice"); 
    actualPrice = parseInt(actualPrice); 

    var converter = 1; 

    if(newVal === "£") { 
     converter = 0.59; 
     console.log("true"); 
    } 

    this.$.price.innerHTML = actualPrice*converter; 
    } 

내가 아래 명령

var a = document.querySelector("gmselect-element"); 
a.setAttribute("currency", "£"); 

답변

2

를 사용하여 통화를 변경 attrChanged 방법 만하여 후킹 시도됩니다 (인 oldval, 된 newval) . 당신이 (attrName, oldVal, newVal)을 얻는 일반적인 attributeChanged lifecycle method을 생성 할 때만입니다. 이것을 시도하십시오 :

currencyChanged: function (oldVal, newVal) { 

    var actualPrice = this.getAttribute("usdprice"); 
    actualPrice = parseInt(actualPrice); 

    var converter = 1; 

    if(newVal === "£") { 
     converter = 0.59; 
     console.log("true"); 
    } 

    this.$.price.innerHTML = actualPrice*converter; 
    } 

this simplified jsbin에서 Dev Tools 콘솔을 열어 작동하는지 확인하십시오.