【发布时间】:2014-01-02 20:17:03
【问题描述】:
我正在使用 Ember,并且需要使用页面上的单选按钮。我查看了许多关于创建 ember 单选按钮的教程和帖子,并且在大多数情况下它们都有效,我似乎无法通过保存单选按钮的状态。当用户选择一个按钮时,视图将会改变,此时添加或减去一个下拉菜单。视图更改没有问题,但单选按钮没有保存它的状态,它们都清楚了。单击相同的单选按钮或“非活动单选按钮”将使它们正常工作。
我使用这个网站作为我的主要参考http://thoughts.z-dev.org/2013/07/04/radio-buttons-in-ember-js/#comment-379
Ember.RadioButton = Ember.View.extend({
tagName: "input",
c: null, //content
type: "radio",
value: null,
attributeBindings: ["name", "type", "value", "checked:unchecked:"],
click: function() {
debugger;
this._context.set('current', this.c);
this.set("selection", this.$().val());
//this.c.gid;
},
checked: function() {
debugger;
return this.get("value") == this.get("selection");
}.property('selection')
});
//App.ShowMeRadio = Ember.ObjectController.extend({
App.ShowMeRadio = Ember.Object.extend({
isSelected: ""
});
App.showMeRadio = App.ShowMeRadio.create();
{{#each content in view._context.groups.content}}
{{view Ember.RadioButton name=content.name selectionBinding="App.showMeRadio.isSelected" cBinding="content" value="name"}}{{content.name}}
{{/each}}
感谢您的帮助
【问题讨论】:
-
checked被定义了两次。首先作为值为 false 的属性,然后作为计算属性。 -
Woops 忘了把它拿出来,检查了一下,该属性是在我写这个问题之前 10 分钟添加的,从昨天开始我一直在尝试不同的东西
标签: javascript ember.js