【发布时间】:2014-04-22 20:59:02
【问题描述】:
每次选中我的模板中的复选框时,我都想向我的聚合物元素添加一个类或更改聚合物元素的属性。
由于我的元素使用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");
}
但是,我不想在此处将其设置为 true,而是要检查复选框的选中属性的值。由于 ID 不是静态的,我无法使用 $ 功能获取元素。我也不知道如何转义绑定在胡子中的数据以在方法中获取其值。
【问题讨论】:
-
谢谢埃里克。为了清楚起见,我添加了更多细节。
标签: polymer