2
后不更新我有允许用户取消选中单选按钮的要求。剑道可观察触发改变事件
我已经创建了清零(取消选中)单选按钮一般功能。这样做后,我使用jQuery触发更改事件,但Observable模型不更新其值。
var UnCheck = "UnCheck";
$("input:radio.AllowUnCheck").click(function(event){
var $clickedbox = $(this),
radioname = $clickedbox.prop("name"),
$group = $('input[name|="'+ radioname + '"]'),
doUncheck = $clickedbox.hasClass(UnCheck),
isChecked = $clickedbox.is(':checked');
if(doUncheck){
$group.removeClass(UnCheck);
$clickedbox.prop('checked', false);
//Edit: Added this code as a work around.
if(kendo)if(this.kendoBindingTarget){
bindingSource = this.kendoBindingTarget.source;
if(bindingSource){
try{
// This assumes that the name of the radio group is the same as the
// as the observables key (set and get key).
bindingSource.set(radioname, "None");
}
catch(e){/*Do nothing*/}
}
};
}
else if(isChecked){
// Make sure that others in the group do not have the UnCheck class
// This will ensure that only one radio in the group will have the UnCheck class at a time.
$group.removeClass(UnCheck);
// Adding the class tells the function to uncheck it the next time this radio
// is clicked, if clicked before any other radio in the group is clicked.
$clickedbox.addClass(UnCheck);
}
//$clickedbox.trigger("change");
document.getElementById(this.id).onchange();
});
我也试着快捷$clickedbox.change()
和document.getElementById("id").onchange();
那么如何我得到的可观测来更新它与UI值时,我已经改变了使用JavaScript的价值?
请记住,这使得变化的代码不知道该元素绑定到剑道观察的,而不能依赖于剑道的UI API。
编辑:我无法找到一个办法解决,所以我加了代码来检查剑道观察到的绑定。继使用的无线电组名称作为访问关键的约定相应的观察到的,我能得到的模型来适当地更新。
请发表您的解决方案作为一个答案为其他用户 – Entreco
@Entreco我说我的解决方案为您的要求。 – Pytry