EXTJS4.0入门学习

来源:互联网 发布:js中设置css样式 编辑:程序博客网 时间:2024/05/21 21:36
(function () {//页面加载完之后会自动执行这个函数    //自定义一个验证器    Ext.apply(Ext.data.validations,{        age:function (config,value) {            if (value === undefined || value === null) {                return false;            }            var size = value,                min    = config.min,                max    = config.max;            if ((min && size < min) || (max && size > max)) {                return false;            } else {                return true;            }        },        ageMessage:'age is not correct'    })    //定义一个model,相当于java中类的概念    Ext.define('Person', {        extend: 'Ext.data.Model',        fields: [            {name: 'name', type: 'string'},            {name: 'age', type: 'int'}        ],        validations:[            {type:'length',field:'name',min:2,max:3},            {type:'age',field:'age',min:0,max:100}        ],        changeName: function () {            var oldName = this.get('name'),                newName = oldName + " The Barbarian";            this.set('name', newName);        }    });    //第一种创建方式    var p = Ext.create('Person', {        name: 'tom',        age: 17    });    //第二种创建方式    var  p2 = Ext.ModelManager.create({        name: 'tom',        age: 17    },'Person');    //当验证不通过时,会返回一个Errors的集合    var errors=p.validate();    errors.each(function (error) {        console.log(error.field+'  '+error.message+'\n');    });})();
0 0
原创粉丝点击