Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.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
Jquery 敲除验证是一种有效的方法_Jquery_Knockout.js - Fatal编程技术网

Jquery 敲除验证是一种有效的方法

Jquery 敲除验证是一种有效的方法,jquery,knockout.js,Jquery,Knockout.js,是否不能在viewmodel中使用isvalid方法?我在无效函数中得到错误isvalid function Student(name,age,country) { var self = this; self.Name = ko.observable(name).extend({ required: true }); self.Age = ko.observable(age); self.Cou

是否不能在viewmodel中使用isvalid方法?我在无效函数中得到错误isvalid

   function Student(name,age,country) {
            var self = this;
            self.Name = ko.observable(name).extend({ required: true });
            self.Age = ko.observable(age);
            self.Country = ko.observable(country);
        };
        /*----------------------------------------------------------------------*/
        /* View Model
        /*----------------------------------------------------------------------*/
        function StudentViewModel() {
            var self = this;
            self.students = ko.observableArray([]);
            self.countries =ko.observableArray([]);
            this.errors = ko.validation.group(this.students, { deep: true });
            self.editingItem = ko.observable();
            self.isItemEditing = function(itemToTest) {
                return itemToTest == self.editingItem();
            };
            self.addStudent = function () {
                var student = new Student("New name","0", self.countries[0]);
                self.students.push(student);

                //  begin editing the new item straight away
                self.editStudent(student);
            };

            self.removeStudent = function (student) {
                if (student.Name()) {
                    if (confirm('Are you sure you wish to delete this item?')) {
                        if (self.editingItem() == null) {
                            self.students.remove(student);
                        }
                    }
                }

            };

            self.editStudent = function (student) {
                // if (self.editingItem() == null) {
                // shows the edit fields
                self.editingItem(student);
                // }
            };

            self.applyStudent = function (student) {
                //  hides the edit fields
                //jQuery("#form1").valid();
                //alert(self.isValid());
                alert(self.isValid());
                if(self.isValid())
                    {
                    self.editingItem(null);
                    }
            };

            self.cancelStudent = function (student) {
                //  hides the edit fields
                self.editingItem(null);
            };

你在使用淘汰验证插件吗?如果是这样,则
StudentViewModel
被包装在一个
ko.validatedObservable()
中,
isValid()
方法位于外部的validatedObservable上
self
指向内部
StudentViewModel
,因此不会定义
isValid()