当属性更改时,Ember 1.0.0 输入类型单选“已检查"绑定未更新 [英] Ember 1.0.0 input type radio 'checked' binding not updated when property changes
问题描述
我遇到了一个问题:我在我的一个模型上有一个名为active"的属性,它是字符串yes"或no",现在我想使用这个属性来检查 HTML单选按钮.
I've got a problem: I've got this property called 'active' on one of my models, it is either the string 'yes' or 'no', now I want to use this property to check a HTML radio button.
因此,当活动"为是"时,应选中它,否则不应选中它.我已经让它工作了,但是当我执行将活动"属性设置为否"或是"的操作时,单选按钮的选中状态不会更新.
So when 'active' is 'yes' it should be checked otherwise it should not be checked. I've got this to work, however when I make an action that sets the 'active' property to 'no' or 'yes' the radio buttons checked status doesn't update.
这是一个垃圾箱:http://emberjs.jsbin.com/ohaSezo/3/edit.
使用复选框时,我得到相同的结果:http://emberjs.jsbin.com/OWILURu/3/edit
When using a checkbox I get the same results: http://emberjs.jsbin.com/OWILUru/3/edit
我无法理解,我认为这应该可行,有什么想法吗?
I can't make sense of it, I think this should work, any ideas?
推荐答案
{{bind-attr}}
不能那样工作 - 它只能以一种方式绑定.以下是您将如何处理的一些示例:
{{bind-attr}}
doesn't work that way - it only binds one way. Here are some examples of how you'd go about this:
使用{{view Ember.Checkbox checkedBinding="car.active"}}
:jsBin 示例
或者使用 Ember.RadioButton
的自定义实现 - {{view Ember.RadioButton checkedBinding="car.active"}}
: jsFiddle 示例
Or use a custom implementation of Ember.RadioButton
- {{view Ember.RadioButton checkedBinding="car.active"}}
: jsFiddle example
感谢 Ember.RadioButton
:Thoughts &软件开发人员的随笔.
根据 Steve H. 的评论更新链接 - 谢谢!
Updated link as per Steve H.'s comment - thanks!
这篇关于当属性更改时,Ember 1.0.0 输入类型单选“已检查"绑定未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!