2012-01-29 78 views
4

我設計了一個基於MVC模式的應用程序。所以我也在我的模型中定義了我的代理,字段和驗證器。這裏有個例子是國家名單的模型:ExtJS 4中的RowEditor數據驗證

型號

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' 
}); 

商店顯示在Grid Panel,wh ERE我使用RowEditor插件,使直接在網格視圖添加和編輯行

網格面板:

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中的rowediting添加驗證功能?

在此先感謝&歡呼聲, 邁克爾

回答

2
+0

嗨阿吉特,感謝您的答覆的方式將上述響應談判......但它也好像一個非常困難的方法來做驗證。我現在發現,我可以直接在字段中爲網格添加驗證。這也可以工作兩次,但是比每個電網控制器中的編碼驗證更好... – Michael 2012-01-29 15:40:14