我有一個視圖模型綁定到我UI淘汰賽後視圖模型不更新UI更新
<div class="editor-label-medium-bold">
<div data-bind="text: 'Cancellation Amount'"></div>
</div>
<div class="editor-field-short">
<div id="CancellationAmount" data-bind="text: CancellationAmount"></div>
</div>
爲CancellationAmount值不會獲取顯示,當ko.applyBindings(XXX)調用。所有這一切都很好。
我有一個JQueryUI日期選擇器,並根據日期的變化,我得到一個取消量的更新數字。這得到正確的價值。
$.ajax({
dataType: "json",
method: "GET",
url: '@Url.Action(MVC.XYZ.ActionNames.GetCancellationAmount, MVC.XYZ.Name)',
data: { date: mdl.CancelDate(), policyid: '@ViewBag.PolicyID' }
})
.done(function (response) {
mdl.CancellationAmount = ko.observable(response);
$('#CancellationAmount').val(response);
})
.fail(function (response) {
alert('fail');
});
「完成」回調中的兩條線都不更新UI。我使用Chrome測試了這一點,並在控制檯中,mdl.CancellationAmount()返回了正確的數字,但UI不會讓步。
我正在解除綁定這個字段並用JQuery手動更新它,就像我試圖在「done」回調的第二行那樣。我認爲,因爲該領域的約束,淘汰賽停止JQuery(也許還有其他......)更新它。
我也許應該提到這行代碼:
mdl.CancellationAmount = ko.observable(mdl.AnnualPremium());
在初始負載,從服務器我的模型發送空的CancellationAmount,所以我複製另一個值,它是一個正的十進制數字,但我解開這個,所以不認爲這是問題。這行只是之前ko.applyBindings(xxx)
有沒有人看過這個之前,或有任何想法如何克服這個問題?
非常感謝你Artem,這是拼圖的最後一塊! –