【问题标题】:save custom radio button state ember保存自定义单选按钮状态 ember
【发布时间】: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


【解决方案1】:

您的RadioButton 视图具有value="name" 属性,它应该是一个简单的词:value=name

【讨论】:

  • weather I have qoutes around name or not ember 将其作为文字字符串,与“content.name”相同,有什么方法可以使用内容中的属性吗?
  • 是的,很抱歉在这种情况下它会是 value=content.name
  • 我在发布我的问题之前尝试过,它仍然将它作为文字字符串。我能够正确阅读内容的唯一方法是添加defaultTemplate: Ember.Handlebars.compile('<label><input type="radio" {{ bindAttr disabled="view.disabled" name="content.name" option="content.gid" value="content.gid" checked="view.checked"}} />{{content.name}}</label>')
猜你喜欢
  • 2014-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多