Javascript Extjs GridPanel验证

Javascript Extjs GridPanel验证,javascript,extjs,extjs4,Javascript,Extjs,Extjs4,当IN1>OU1或IN2>OU2时,如何执行验证函数以获得错误 这是我的代码(带有roweditor插件的网格面板) 我认为最好的方法是使用field的配置: 不要使用getCmp(除非调试,否则永远不要使用getCmp),而是从存储中获取要与值进行比较的数据。我刚刚尝试过,但收到了以下错误:Ext.getCmp(“editF02ORAOU1”)。getValue()为空,但在我的网格中,所有行的所有列中都有数据!我该怎么办?@jack,我已经更新了我的答案,并为你的例子添加了非常感谢的内容!!

当IN1>OU1或IN2>OU2时,如何执行验证函数以获得错误

这是我的代码(带有roweditor插件的网格面板)


我认为最好的方法是使用field的配置:


不要使用getCmp(除非调试,否则永远不要使用getCmp),而是从存储中获取要与值进行比较的数据。

我刚刚尝试过,但收到了以下错误:Ext.getCmp(“editF02ORAOU1”)。getValue()为空,但在我的网格中,所有行的所有列中都有数据!我该怎么办?@jack,我已经更新了我的答案,并为你的例子添加了非常感谢的内容!!我试过了,但不知道为什么会收到这个错误:值未定义[Interrompi per questo error]返回函数.prototype….ctor.apply(Function.prototype,args);如果您想在表单验证期间验证网格是否包含记录(在这种情况下,它是有效的)?您能给我举个例子吗?我想这应该是另一个答案下面的注释。这样(断章取义)感觉很奇怪。也许你没有足够的代表发表评论。。。这里有一些。
{
 xtype: 'gridpanel',
 height: 250,
 width: 400,
 title: 'My Grid Panel',
 columns: [
           {
             xtype: 'datecolumn',
             text: 'IN1',
             dataindex 'F02ORAIN1',
             field: {
               xtype: 'timefield',
               id 'editF02ORAIN1'
             }
           },
           {
             xtype: 'datecolumn',
             dataindex 'F02ORAOU1',
             text: 'OU1',
             field: {
               xtype: 'timefield',
               id 'editF02ORAOU1'
             }
           },
           {
              xtype: 'datecolumn',
              text: 'IN2',
              dataindex 'F02ORAIN2',
              field: {
                xtype: 'timefield',
                id 'editF02ORAIN2'
              }
           },
           {
             xtype: 'datecolumn',
             text: 'OU2',
             dataindex 'F02ORAOU2',
             field: {
               xtype: 'timefield',
               id 'editF02ORAOU2'
            }
          }
 ],
 plugins: [
    Ext.create('Ext.grid.plugin.RowEditing', {
    })
 ]
}
// ...
{
    xtype: 'datecolumn',
    text: 'IN1',
    dataIndex: 'F02ORAIN1',
    field: {
        xtype: 'timefield',
        id: 'editF02ORAIN1',
        validator: function(value) {
            if (!Ext.getCmp('editF02ORAOU1').getValue()) return true;
            if (this.getValue() > Ext.getCmp('editF02ORAOU1').getValue())
              return 'IN1 should be less then OU1';
            return true;
        }
    }
}, {
    xtype: 'datecolumn',
    dataIndex: 'F02ORAOU1',
    text: 'OU1',
    field: {
        xtype: 'timefield',
        id: 'editF02ORAOU1'
    }
},
// ...