我想创建一个自定义的淘汰验证规则,该规则将获取当前可观察值,与之比较的值以及条件.
我在网上看到的所有示例都只有两个参数传递到自定义验证中.
我已经做了一个解决方法来传递一个数组,其值为compare和条件,但这有点笨拙.我的消息格式也输出数组中的值,而不仅仅是otherVal.
例如:
/*
* Compares two values only if the specified condition is true.
* Parameters:
* array[0] - otherVal
* array[1] - conditional
*
* Returns:
* true if the condition is false.
* true if the condition is true AND val is lessThanOrEqualTo otherVal
* false otherwise
*
* Usage:
* Used to validate observables conditionally.
*
* Example:
* self.salary = ko.observable().extend({
mustLessThanOrEqualConditional: [100, isFieldEditable]})
*/
ko.validation.rules['mustLessThanOrEqualConditional'] = {
validator: function(val, array) { …Run Code Online (Sandbox Code Playgroud) 我有一个模态,我需要使用敲除验证验证一些输入.单击提交按钮时,将调用一个验证数据的函数.预计具有以下功能:
如何在函数内部关闭模态?