Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Polymer 聚合物属性变化函数_Polymer_Web Component - Fatal编程技术网

Polymer 聚合物属性变化函数

Polymer 聚合物属性变化函数,polymer,web-component,Polymer,Web Component,我有一个用货币和价格属性定义的元素。当我将货币属性设置为英镑时,我想相应地计算价格。我尝试挂接attrChanged方法,但if条件从未记录为true currencyChanged: function (attrName, oldVal, newVal) { var actualPrice = this.getAttribute("usdprice"); actualPrice = parseInt(actualPrice); var converter = 1;

我有一个用货币和价格属性定义的元素。当我将货币属性设置为英镑时,我想相应地计算价格。我尝试挂接attrChanged方法,但if条件从未记录为true

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", "£");
使用like
currencyChanged
时,参数为(oldVal,newVal)。只有在创建泛型时才能获得(attrName、oldVal、newVal)。试试这个:

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;
  }
打开上的Dev Tools控制台,查看它是否正常工作