2014-04-22 85 views
3

每次選中我的模板中的複選框,我想添加一個班級到我的聚合物元素或更改聚合物元素的屬性。添加班級到聚合物元素

由於我的元素使用label for屬性,我綁定的複選框的ID在我的標記實例化元素時

<label for="{{uniqueid}}" on-tap="{{toggle}}" /> 
    <input type="checkbox" id="{{uniqueid}}" class="select" checked="{{checker}}"> 
    <img src="{{image}}" alt="" class="prod-img"> 
    <div class="grid-details"> 
    <span>{{designer}}</span> 
    <span>{{product}}</span> 
    <span>{{currency}} {{price}}</span> 
    <span>Shipped from {{info}}</span> 
    </div> 
</label> 

我會再打電話像這樣

<gmselect-element uniqueid="four" image="http://i.imgur.com/fkq1QKq.jpg" designer="CUCARELIQUIA" product="Castellano Suede Bag Redder" info="Gijon, Spain" price="650" currency="$"></gmselect-element> 

我切換元素功能看起來像下面

toggle: function() { 
    this.$.grid.setAttribute("class", "grid true"); 
    this.setAttribute("selected", "true"); 
    } 

但是,instea在這裏將它設置爲true,我想檢查複選框的選中屬性的值。由於ID不是靜態的,我不能使用$功能獲取元素。我也不知道如何逃避鬍鬚中的數據綁定,以在方法中獲得它的價值。

+0

感謝埃裏克。我已經添加了更多細節來說明問題。 –

回答

4
this.$.grid.classList.add('classname') 

this.$.grid.classList.remove('classname') 
+0

來引用它,只需爲舊版瀏覽器編寫classList.add或remove()就會有一些支持問題。只是爲可能遇到此問題的人提供幫助。 – TheeBen