0

我正在为需要一些验证的表单创建模型。

该模型如下所示:

//Defining a data structure for the Work Item List
Ext.define('InfoImage.model.configure.configModel', {
    extend : 'Ext.data.Model',

    config : {
        //Defining the fields required in the Work Item List
        fields : [ 'servname', 'port', 'protocol', 'username', 'password',
                'domain', 'appconfig', 'apptitle', 
                'appconfig' ],

        validations : [ 
        {
            type : 'presence',
            name : 'servname'
        }, 
        {
            type : 'presence',
            name : 'port'
        //  matcher : /[0-9]{4}[A-Z]+/
        }, 
        {
            type : 'presence',
            name : 'username'
        },
        {
            type : 'presence',
            name : 'password'
        }],
        proxy : {
            type : 'localstorage',
            id : 'configId'
        }
    }
});

我尝试通过调用验证

Ext.getCmp('form').validate();

但它说它没有称为验证的方法。

sencha 是否提供验证方法?如果是,我该如何实现?

4

1 回答 1

1

Sencha 确实提供了一种验证模型的方法。阅读文档:http ://docs.sencha.com/touch/2-0/#!/guide/models-section-3

我猜你可以使用form.getValues()来填充一个新模型,然后在模型上使用 validate() 方法来验证数据。

于 2012-05-29T09:19:29.767 回答