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