[英]How to bind paper-toggle-button state to its label - Polymer
I currently have several paper-toggle-button
elements that receive their checked
state via an iron-ajax
GET, bringing JSON data of a true/false nature to set the toggles on/off respectively. 我目前有几个
paper-toggle-button
元素,通过iron-ajax
GET接收其checked
状态,带来真/假性质的JSON数据,分别设置切换开/关。
I have labels next to the buttons to display their toggled state also, with these taking the same data as the toggles themselves. 我在按钮旁边有标签来显示它们的切换状态,这些标签采用与切换本身相同的数据。 However, I would like to change this so that the labels are bound to the current state of the toggle rather than the back-end JSON data.
但是,我想更改此设置,以便标签绑定到切换的当前状态而不是后端JSON数据。
Is this at all possible? 这是可能吗?
HTML HTML
<paper-toggle-button id="approver" checked$="{{current.approver}}">{{current.approver}}</paper-toggle-button>
<paper-toggle-button id="askExpert" checked$="{{current.askExpert}}">{{current.askExpert}}</paper-toggle-button>
<paper-toggle-button id="autoConnect" checked$="{{current.Autoconnect}}">null{{current.Autoconnect}}</paper-toggle-button>
<paper-toggle-button id="beExpert" checked$="{{current.beExpert}}">{{current.beExpert}}</paper-toggle-button>
You're using attribute binding for checked
(ie, checked$="{{flag}}"
), but checked
is actually a property, so you should use property binding (ie, checked="{{flag}}"
) for proper data-binding notifications. 你正在使用属性绑定来
checked
(即, checked$="{{flag}}"
),但是checked
实际上是一个属性,所以你应该使用属性绑定(即, checked="{{flag}}"
)适当的数据绑定通知。 Note the removed $
from the binding: 请注意绑定中删除的
$
:
<paper-toggle-button id="approver" checked="{{current.approver}}">{{current.approver}}</paper-toggle-button>
<paper-toggle-button id="askExpert" checked="{{current.askExpert}}">{{current.askExpert}}</paper-toggle-button>
<paper-toggle-button id="autoConnect" checked="{{current.Autoconnect}}">{{current.Autoconnect}}</paper-toggle-button>
<paper-toggle-button id="beExpert" checked="{{current.beExpert}}">{{current.beExpert}}</paper-toggle-button>
I believe the behavior you're seeking would be achieved simply by fixing the binding type indicated above. 我相信你所寻求的行为只需通过修复上面指出的绑定类型即可实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.