Polymer 向聚合元素添加一个类
每次选中模板中的复选框时,我都希望向聚合元素添加一个类或更改聚合元素的属性 由于我的元素对属性使用Polymer 向聚合元素添加一个类,polymer,Polymer,每次选中模板中的复选框时,我都希望向聚合元素添加一个类或更改聚合元素的属性 由于我的元素对属性使用标签,因此在标记中实例化元素时,我将复选框的ID绑定到 <label for="{{uniqueid}}" on-tap="{{toggle}}" /> <input type="checkbox" id="{{uniqueid}}" class="select" checked="{{checker}}"> <img src="{{image}}" alt="
标签,因此在标记中实例化元素时,我将复选框的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>
但是,我想检查复选框的checked属性的值,而不是在这里将其设置为true。因为ID不是静态的,所以我无法使用$functional获取元素。我也不知道如何在moustach中转义绑定的数据以在方法中获取其值。您已经将选中的值绑定到{checker}
,因此您应该能够在切换
函数中引用this.checker
如果需要,还可以从事件中获取模型数据。见:
谢谢,它成功了。我不知道您可以使用this
属性来引用它。我已经添加了更多的细节来说明这一点。对于较旧的浏览器,简单地编写classList.add或remove()存在一些支持问题。只是提醒那些可能遇到这种情况的人。
<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");
}
this.$.grid.classList.add('classname')
this.$.grid.classList.remove('classname')