knockoutjs with绑定导致unobtrusive validation失效的问题
2013-09-02 22:42
399 查看
如果最初的时候with绑定的对象是空的,那么with绑定内部的unobtrusive validation规则在提交的时候无法生效,无法进行验证。
解决办法:
在提交的时候(或者with绑定的对象非空值以后),先清除form对象的'validation'的data:
$.removeData($form[0], 'validator');
然后调用unobtrusive validation的parse函数重新对form内的控件进行解析。
$.validator.unobtrusive.parse($form[0]);
再调用valid()函数就可以正常验证了。
with绑定的对象为空的时候,还会导致form内button(或其他控件)的jquery的事件处理代码不能正常触发。需要把button移动到with绑定范围之外。
knockoutjs 对with 的说明:
If the expression you supply evaluates to
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.
解决办法:
在提交的时候(或者with绑定的对象非空值以后),先清除form对象的'validation'的data:
$.removeData($form[0], 'validator');
然后调用unobtrusive validation的parse函数重新对form内的控件进行解析。
$.validator.unobtrusive.parse($form[0]);
再调用valid()函数就可以正常验证了。
with绑定的对象为空的时候,还会导致form内button(或其他控件)的jquery的事件处理代码不能正常触发。需要把button移动到with绑定范围之外。
knockoutjs 对with 的说明:
If the expression you supply evaluates to
nullor
undefined, descendant elements will not be bound at all, but will instead be removed from the document.
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.
相关文章推荐
- 关于 js 动态生成html 绑定事件失效的问题
- 绑定控件导致程序崩溃的问题:Error: no data exchange control with ID 0x%04X.
- 关于js的Date.getFullYear()导致其余代码失效的问题
- 解决VUE框架 导致绑定事件的阻止冒泡失效问题
- ajax动态加载js,导致js不执行失效问题阜
- ajax动态加载js,导致js不执行失效问题吻
- js引用里面再写绑定blur事件导致代码失灵的问题备忘
- 【js学习之路】事件绑定函数中,将this换成调用对象导致的问题
- 编码问题导致js失效
- 一个js导致的jquery失效问题的解决方法
- ajax动态加载js,导致js不执行失效问题颇
- AngularJS动态增加dom,导致里面ng-click、modal绑定失效的问题解决方法
- 样式文件跨域导致Respond.js插件在IE浏览器失效的问题
- 一个js导致的jquery失效问题的解决方法
- Bootstrap框架使用iframe及jQuery中load方法导致js失效问题
- servlet跳转页面导致css,js等失效的问题
- ajax动态加载js,导致js不执行失效问题
- 记录问题:ajax局部刷新页面,导致js事件失效
- js动态生成的DOM绑定事件失效的问题
- jQuery 重复加载,导致依赖于 jQuery的JS全部失效问题