退出视图后,“余烬”单选按钮永远不会被清除

Ember radio button never be cleared after exiting the view

本文关键字:永远 清除 单选按钮 视图 余烬 退出      更新时间:2023-09-26

我有一个带有 5 个单选按钮的车把:

<ui>
            <li> <label>
            {{view Ember.RadioButton  id="option1" name="selectionTest" selectionBinding="isSelected" value=1}}
            <b>{{i18n 'kwoption1'}}</b>
        </label></li>
       <li> <label>
            {{view Ember.RadioButton id="option2" name="selectionTest" selectionBinding="controllerisSelected" value=2 valueBinding="radio1"}}
            <b>{{i18n 'kwoption2'}}</b>
        </label></li>
            <li> <label>
            {{view Ember.RadioButton id="option3" name="selectionTest" selectionBinding="isSelected" value=3}}
            <b>{{i18n 'kwoption3'}}</b>
        </label></li>
        <li> <label>
            {{view Ember.RadioButton id="option4" name="selectionTest" selectionBinding="isSelected" value=4}}
            <b>{{i18n 'kwoption4'}}</b>
        </label></li>
        <li> <label>
            {{view Ember.RadioButton id="option5" name="selectionTest" selectionBinding="isSelected" value=5}}
            <b>{{i18n 'kwoption5'}}</b>
        </label></li>
        </ui>

当我单击提交按钮时,它会清除所有单选按钮,但在退出屏幕并尝试再次访问它后,我得到了旧的选定值。

如何清除此车把上的缓存?

在提交操作中,调用一个方法,该方法在不再需要值之后但在转换路由之前清除所有选择。

最后,

我通过将选择值设置为"来将init函数添加到Ember.RadioButton,从而解决了该问题,如下所示:

Ember.RadioButton = Ember.View.extend({
    tagName : "input",
    type : "radio",
    attributeBindings : [ "name", "type", "value", "checked:checked:" ],
    click : function() {
        cValue=(this.set("selection", this.$().val()).value).toString();
        this.set("selection", this.$().val());
    },
    init: function() {
        cValue=null;
        this.set("selection", "");
    },
    checked : function() {
        return this.get("value") == this.get("selection");  
    }.property()
});

感谢大家为您的公司