若是最初的時候with綁定的對象是空的,那麼with綁定內部的unobtrusive validation規則在提交的時候沒法生效,沒法進行驗證。jquery
解決辦法:express
在提交的時候(或者with綁定的對象非空值之後),先清除form對象的'validation'的data:函數
$.removeData($form[0], 'validator');lua
而後調用unobtrusive validation的parse函數從新對form內的控件進行解析。spa
$.validator.unobtrusive.parse($form[0]);code
再調用valid()函數就能夠正常驗證了。orm
with綁定的對象爲空的時候,還會致使form內button(或其餘控件)的jquery的事件處理代碼不能正常觸發。須要把button移動到with綁定範圍以外。對象
knockoutjs 對with 的說明:事件
If the expression you supply evaluates to null
or undefined
, descendant elements will not be bound at all, but will instead be removed from the document.element
If the expression you supply involves any observable values, the expression will be re-evaluated whenever any of those observables change. Then, descendant elements will be cleared out, and a new copy of the markup will be added to your document and bound in the context of the new evaluation result.