Jquery Backbonejs-未正确调用函数

Jquery Backbonejs-未正确调用函数,jquery,validation,backbone.js,Jquery,Validation,Backbone.js,我正在做一个主干测试应用程序。我决定验证它。我正在使用一个著名的验证thedersen的主干。验证,但它不能正常工作。这是我的消息来源有人能帮我解决这个问题吗 jQuery(document).ready(function($) { _.extend(Backbone.Validation.callbacks, { //is this wrong place? valid: function (view, attr, selector) { co

我正在做一个主干测试应用程序。我决定验证它。我正在使用一个著名的验证thedersen的主干。验证,但它不能正常工作。这是我的消息来源有人能帮我解决这个问题吗

jQuery(document).ready(function($) {

    _.extend(Backbone.Validation.callbacks, { //is this wrong place?
        valid: function (view, attr, selector) {
            console.log("valide"); //i am not getting any console
        },
        invalid: function (view, attr, error, selector) {
           console.log('not valide'); //i am not getting any console
        }
    });



    var Person = Backbone.Model.extend({
        defualts : {
                    first_name : 'qwe',
                    last_name : 'ewq',
                    id : 0
        },
        validation: {
            first_name: {
              required: true,
              msg: 'Please enter a valid first_name'
            },
            last_name: {
              required: true,
              msg: 'Please enter a valid last_name'
            }
        }

    });

    var PersonCollection = Backbone.Collection.extend({
            model : Person
        });

    var idGen = 1;

    var PersonView = Backbone.View.extend({
        el : $("#personDisplay"),
        tmpl : _.template($("#personTemplate").html()),
        editTmpl : _.template($("#editPersonTemplate").html()),
        initialize:function(){

        },
        render : function() {
            if (this.model.id != 0) {
                    $(this.el).append(this.tmpl(this.model.toJSON()));
            } else {
                    $(this.el).append(this.editTmpl(null));


               }

//when below uncommitted it works, but i am getting 3 consoles.

                // var isValid = this.model.isValid('first_name');  
                // console.log('isValid', isValid);
        }
    });         

     var PersonMasterView = Backbone.View.extend({

            el : $("#displayForm"),
            editTmpl : _.template($("#editPersonTemplate").html()),

            events : {
                    "click #addUser" : "addUsr",
                    "click #save" : "add"
            },

            initialize : function() {

                    this.collection = new PersonCollection();
                    this.render();
                    Backbone.Validation.bind(this);
            },

            render : function() {
                    //
                    $("#personDisplay").html('');

                    _.each(this.collection.models, function(item) {
                            //alert('collection iteratin->'+item.id);
                            var perView = new PersonView({
                                    model : item
                            });
                            perView.render();
                    }, this);

            },

            add : function(e) {
                    e.preventDefault();
                    idGen = idGen + 1;
                    var data = (Backbone.Syphon.serialize(this));
                    var that = this;
                    data.id = idGen;
                    // console.log(data);
                    this.collection.add(data);
                    this.render();
            },

            addUsr : function() {
                    var prsn = new Person({
                            id : 0
                    });
                    this.collection.add(prsn);
                    this.render();
            }
    });

    var pView = new PersonMasterView();
    Backbone.Validation.bind(pView);

});

我更新代码如下:工作正常。多谢大家

var PersonView = Backbone.View.extend({
        el : $("#personDisplay"),
        tmpl : _.template($("#personTemplate").html()),
        editTmpl : _.template($("#editPersonTemplate").html()),
        initialize:function(){
            Backbone.Validation.bind(this);
        },
        render : function() {

            var status = this.model.isValid(true);

            if (this.model.id != 0) {
                    $(this.el).append(this.tmpl(this.model.toJSON()));
            } else {
                    $(this.el).append(this.editTmpl(null));
            }
        }
    });