ext的getValue()和getRawValue()的区别

来源:互联网 发布:傅园慧网络直播 编辑:程序博客网 时间:2024/05/02 00:58
一. ExtJS DateField 中getValue()和getRawValue()
采用Ext.Ajax.request()提交日期格式的字段值时  用getValue()得到的datefield控件中的值是带时分秒格式的标准时间(例:2010-09-10T00:00:00)。故可以getValue()后再将获取的数据format。


如果DateField有统一的格式化(比如:Y-m-d),用getRawValue方法代替getValue即可,用getRawValue( )得到的就是去掉了时分秒的我们期待的值 2010-09-10。


items: [{
            columnWidth: .25,
            layout: 'form',
            border: false,
            style: 'padding-right: 50px',
            items: [{
                xtype: 'datefield',
                fieldLabel: '工作日',
                width: 150,
                id: 'workdateQuery',
                anchor: '100%',
                format: 'Ymd'
            }]
        }]


此时,得到的值Ext.getCmp(“workdateQuery”).getRawValue()即可得到20121010.【个人认为getRawValue即文本框中显示的值,是经过format之后的展示给用户的值】


 
二. ExtJS ComboBox 中getValue()和getRawValue()
 
1. ExtJS的ComboBox是一个更接近Form程序的ComboBox的控件,因为它除了有正常的下拉式选择框之外,还支持键盘输入,等于是textbox和comboBox的结合。此外,ExtJS的ComboBox还支持对选项的自动联想。
但是当把Ext.form.ComboBox 的editable 设为true之后,用getValue()是取不到人工打进去(edit)的值的。因此,对于带可编辑功能的ComboBox,我们可以用getRawValue() 去取得值。
我们先来看看两个Method的原型和说明:
getRawValue() : Mixed
Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see getValue().
getValue() : String
Returns the currently selected field value or empty string if no value is set.
注意:虽然getValue()返回的类型是String,而getRawValue()返回的是Mixed,但是这个Mixed可以被当作String运算和处理。
 
2.在做项目是遇到一个问题: 
ComboBox是可以手动输入的,输入时按前缀方式查询, 
缺点是必须选中下拉框的一项,如果不是选择而是手工输入完整代码,查询时getValue得到的是undefined,改为用getRawValue解决此问题。 原因是getValue是从ComboBox的store中用getById取数据,如果不选择,getById返回的是undefined。 
 
3.在combobox中如果设置了valueField和displayField,则getValue()返回的是valueFiled的值,getRawValue()返回的则是displayField的值。
 



















































0 0
原创粉丝点击