您的位置:首页 > Web前端 > JavaScript

ExtJS 3.4 form表单中isDirty()的使用方法

2014-10-08 10:13 246 查看
isDirty() : Boolean

Returns true if any fields in this form have changed from their original values.

Note that if this BasicForm was configured with
trackResetOnLoad then theFields' original values are updated when the values are loaded bysetValuesor

loadRecord.

Parameters:

None.

Returns:
Boolean


以前写过同样的一个问题,不是很全面,解释的也不明确。现在整理一下:


在form表单中,判断是否表格中的数据发生变化,可以使用isDirty()方法。


注意:如果表单中字段是原始的值,没有改变,即:数据刚load完,这个时候为原始值;


如果数据在load完后,又进行了setValue操作,则数据发生改变,isDirty返回的值为:true;


这样就无法使用isDirty;所以如果想使用isDirty进行判断是,需没有set表格值;


此外还有
 需在formPanel 必须配置trackResetOnLoad
为true;



如下:




如果在load数据时,对表单中的数据进行setValue:
    personForm.load({
                    url : 'xxxxx',
                    success : function(form, action) {
                        var json = Ext.decode(action.response.responseText);
                        personForm.getTopToolbar().getComponent('personInfoStatus').setValue(json.rows[0].status);
                        personForm.getForm().findField('experience').setValue(json.rows[0].experience);
                     },
                    failure : function(response, options) {                    
                        Ext.Msg.alert("提示信息", "不在转正定级范围内!");
                    }
                })


那么:



if (personForm.getForm().isDirty()) {
Ext.Msg.alert('提示', '请对数据进行修改');
return;
}
将始终会提示“请对数据进行修改”
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: