我知道淘汰赛通常只会在控件失去焦点时更新文本框绑定。我有一个keydown
附加到几个文本框的事件,并且模型没有更新当前焦点文本框中的值。如何在keydown
事件期间强制模型使用文本框中的值进行自我更新?
$('.mySelector').on('keydown', function(event) {
if (event.which == 13) { // enter was pressed
event.preventDefault();
$.ajax({
type: 'POST',
url: 'pathToCall',
// model.Query still has the old text from before the keydown event since the
// text box has not lost focus yet
data: "{parameterName: " + JSON.stringify(ko.mapping.toJS(model.Query)) + "}",
function (data) {
model.SearchResults(data.d);
},
function () { alert('error'); }
});
});