Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Knockout.js 嵌套数据结构中的敲除验证_Knockout.js_Knockout Validation - Fatal编程技术网

Knockout.js 嵌套数据结构中的敲除验证

Knockout.js 嵌套数据结构中的敲除验证,knockout.js,knockout-validation,Knockout.js,Knockout Validation,我有一个表单的viewmodel,我正试图使用敲除验证来添加验证。 开始时间 结束时间 添加行 我需要验证,如果我在第1行中输入“结束时间”,并且当我添加新行时,第2行的开始时间必须大于第1行的结束时间。如果您希望在向数组添加新项时验证组不起作用,则需要使用选项deep。您可以通过将验证组包装在一个可观察的文件中,并使用“计算”来启用或禁用“保存”按钮来解决此问题 <table data-bind='visible: slots().length > 0'> <

我有一个表单的viewmodel,我正试图使用敲除验证来添加验证。


开始时间
结束时间
添加行

我需要验证,如果我在第1行中输入“结束时间”,并且当我添加新行时,第2行的开始时间必须大于第1行的结束时间。

如果您希望在向数组添加新项时验证组不起作用,则需要使用选项deep。您可以通过将验证组包装在一个可观察的文件中,并使用“计算”来启用或禁用“保存”按钮来解决此问题

<table data-bind='visible: slots().length > 0'>
<thead>
        <tr>
            <th>Start Time</th>
            <th>End Time</th>
       </tr>
    </thead>
    <tbody data-bind='foreach: slots'>
        <tr>
            <td><input type="text" class="input-medium time-picker" data-bind='value: start_time' required="true"/></td>
            <td><input type="text" class="input-medium time-picker" data-bind='value: end_time' required="true"/></td>
            <td><a href='#' data-bind='click: $root.removeSlot'><i class="icon-minus-sign"/></a></td>
        </tr>
    </tbody>
</table>
<button class="btn btn-primary" data-bind='click: addSlot'>Add Row</button>
ViewModel = function() {
    this.error = ko.observable();
    this.items = ko.observableArray();
    this.items.subscribe(this.onAdded, this); 

    this.canSave = ko.computed(this.getCanSave, this);
};

ViewModel.prototype = {
    onAdded: function() {
        this.error(ko.validation.group(this));
    },
    add: function() {
        this.items.push(new ItemViewModel());
    },
    getCanSave: function() {
        return this.error() && this.error()().length === 0;
    }
}