骨干验证向验证添加输入

时间:2014-07-28 07:08:32

标签: javascript backbone.js

我有一个骨干模型,其中包含验证对象和验证参数列表。

var SignUpModel = Backbone.Model.extend({    
  validation: {    
    firstname: {
        required: true,
         pattern: 'name'
    },
    lastname: {
        required: true,
        pattern: 'name'
    }    
  },

  addToValidation: function(){         
     // HOW TO DO THIS???
     this.validation.PUSH{
      country: {
         required: true
      },
      phone: {
        required: true,
        pattern: 'phone'
      }
    }
  }    
});

如何将另一个对象添加到此对象?我在JS中找不到它,但是这个函数可能存在于Backbone或Underscore中吗?

也许骨干网有特殊的数据保存功能?

1 个答案:

答案 0 :(得分:2)

_.extend(this.validation, {
   country : {
     required: true
  },
  phone: {
    required: true,
    pattern: 'phone'
  }
});