zoukankan      html  css  js  c++  java
  • 在设置或存储属性的时候进行数据校验

     1 Person = Backbone.Model.extend({
     2     //如果从validate中返回字符串了,Backbone就会抛个实例异常
     3     validate: function(attributes) {
     4         if (attributes.age < 0 && attributes.name != "Dr Manhatten") {
     5             return '你的存在是个错误';
     6         }
     7     },
     8     initialize: function() {
     9         console.log('欢迎来到这个报错的世界!');
    10         this.bind('error', function(model, error) {
    11             //收到个错误,记录,警告,然后忘记它
    12             console.log(error);
    13         });
    14     }
    15 });
    16 
    17 var person = new Person;
    18 person.set({
    19     name: 'Mary Poppins',
    20     age: -1
    21 });
    22 
    23 //会触发error,输出警告
    24 delete person;
    25 
    26 var person = new Person;
    27 person.set({
    28     name: 'Dr Manhatten',
    29     age: -1
    30 })
  • 相关阅读:
    gauss消元
    POJ1229 域名匹配
    HDU3487 play with chain
    POJ1185 炮兵阵地
    POJ2411
    sgu233 little kings
    树形DP初步-真树1662
    树形DP初步-二叉树1661
    c++——string类用法
    UVa1354 ——天平难题
  • 原文地址:https://www.cnblogs.com/qzsonline/p/2641966.html
Copyright © 2011-2022 走看看