jQuery Mobile的淘汰赛和提交表单绑定
我在knockoutjs和jQuery移动之间存在明显的不兼容迷迷糊糊说到表单提交行为。
I stumbled on an apparent incompatibility between knockoutjs and jquery mobile when it comes to form submit behavior.
考虑下面的标记:
<form data-bind="submit: myKoSubmitAction">
<!-- form fields here -->
</form>
的意图是,淘汰赛prevents服务器后/获取,而是调用myKoSubmitAction。 JQM也将prevent标准仅适用于JQM的原因提出的行为是表单提交由一个Ajax请求更换。
The intention is that knockout prevents server post/get and instead calls myKoSubmitAction. jqm will also prevent standard submit behavior only for jqm the reason is that the form submit is replaced by an ajax request.
所以,当敲除(presumably)成功在preventing标准服务器的请求时,它未能prevent JQM发送Ajax请求。
So while knockout (presumably) succeeds at preventing the standard server request, it fails to prevent jqm from sending an ajax request.
我找到了答案,一个谷歌集团这个问题,并认为这应该是左右为好。见下面
I found the answer to this problem in a google group and thought it should be on SO as well. See below
我已经能够找到最好的解决方案是以下自定义こ绑定:
The best solution I have been able to find is the following custom ko binding:
//This binding fixes apparent incompatibility between knockout and jqm
ko.bindingHandlers.jqmsubmit = {
init: function (el, accessor, allbindings, vm) {
ko.bindingHandlers.submit.init(el, accessor, allbindings, vm);
$(el).submit(function (e) {
// prevent the submit behavior
e.preventDefault();
e.stopPropagation();
return false;
});
}
};
要在标准的地方使用提交こ绑定:
To be used in the place of the standard submit ko binding:
<form data-bind="jqmsubmit: myKoSubmitAction">
<!-- form fields here -->
</form>