Validation ExtJS4中的RowEditor数据验证

Validation ExtJS4中的RowEditor数据验证,validation,extjs,model,extjs4,store,Validation,Extjs,Model,Extjs4,Store,我设计了一个基于MVC模式的应用程序。因此,我还在模型中定义了代理、字段和验证器。例如,这里是一个国家列表的模型: 型号 Ext.define('LT.model.Country',{ extend: 'Ext.data.Model', fields: [{name: 'id',type: 'int'}, {name: 'name', type: 'string'}, ], validations: [ {type:

我设计了一个基于MVC模式的应用程序。因此,我还在模型中定义了代理、字段和验证器。例如,这里是一个国家列表的模型:

型号

Ext.define('LT.model.Country',{

    extend: 'Ext.data.Model',
    fields: [{name: 'id',type: 'int'},
             {name: 'name', type: 'string'},
    ],

    validations: [
        {type: 'length', field: 'name', min: 2}
    ],

    proxy: {
        type: 'rest',
        url: '/country',
        reader: {
            type: 'json'
        },
        writer: {
            type: 'json'
        }    
   }
});
以下是使用此模型的商店:

商店:

Ext.define('LT.store.Country', {
    extend: 'LT.base.store.Base',
    model:  'LT.model.Country'
});
    Ext.define('LT.view.country.List' ,{
    extend: 'Ext.grid.Panel',
    alias : 'widget.country-list',
    plugins: [
        Ext.create('Ext.grid.plugin.RowEditing', {
            clicksToEdit: 2,
            clicksToMoveEditor: 1
        })
    ],
    store : 'Country',

    columns: [
            {header: 'ID',  dataIndex: 'id', width: 50},
            {header: 'Name', dataIndex: 'name', flex: 3, editor: 'textfield'},

    ],
    tbar: [{
        xtype: 'button',
        action: 'add',
        text: 'Add'
    },{
        xtype: 'button',
        action: 'delete',
        text: 'Delete'
    }]

});
存储区显示在网格面板中,我使用行编辑器插件在网格视图中直接添加和编辑行

网格面板:

Ext.define('LT.store.Country', {
    extend: 'LT.base.store.Base',
    model:  'LT.model.Country'
});
    Ext.define('LT.view.country.List' ,{
    extend: 'Ext.grid.Panel',
    alias : 'widget.country-list',
    plugins: [
        Ext.create('Ext.grid.plugin.RowEditing', {
            clicksToEdit: 2,
            clicksToMoveEditor: 1
        })
    ],
    store : 'Country',

    columns: [
            {header: 'ID',  dataIndex: 'id', width: 50},
            {header: 'Name', dataIndex: 'name', flex: 3, editor: 'textfield'},

    ],
    tbar: [{
        xtype: 'button',
        action: 'add',
        text: 'Add'
    },{
        xtype: 'button',
        action: 'delete',
        text: 'Delete'
    }]

});
我现在的问题是,如果在网格视图中编辑数据,验证错误不会显示。如果数据与验证标准不匹配,则不会将其提交给代理(这很好),但用户也不会收到错误消息,即插入的数据无效

我发现了一些(不是很好的)解决方法——但也许有人知道另一种在extjs中向行编辑添加验证功能的解决方案吗

提前感谢,干杯, 迈克尔


上面的回复谈到了您可以遵循的方法

嗨,阿吉特,谢谢您的回复。。。但这似乎也是一种很难验证的方法。现在我发现,我可以直接在网格中为字段添加验证。这也可以工作两次,但比在控制器中为每个网格编码验证更好。。。