Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
模型ID为0时的ExtJS textfield或combobox defaultValue_Extjs_Extjs4_Extjs4.1_Extjs4.2_Extjs Mvc - Fatal编程技术网

模型ID为0时的ExtJS textfield或combobox defaultValue

模型ID为0时的ExtJS textfield或combobox defaultValue,extjs,extjs4,extjs4.1,extjs4.2,extjs-mvc,Extjs,Extjs4,Extjs4.1,Extjs4.2,Extjs Mvc,在我的应用程序(ExtJS4.2.1)中,我有一个创建新记录并将其保存到数据库的窗口 创建并显示窗口时,我会创建一个新记录并将其分配给窗口窗体记录: onNewPunchClick: function(button, e, options) { var me = this; var win = Ext.create('App.view.attendance.punch.EditPunch'), editForm = win.down('

在我的应用程序(ExtJS4.2.1)中,我有一个创建新记录并将其保存到数据库的窗口

创建并显示窗口时,我会创建一个新记录并将其分配给窗口窗体记录:

 onNewPunchClick: function(button, e, options) {
        var me = this;

        var win = Ext.create('App.view.attendance.punch.EditPunch'),
            editForm = win.down('#editForm');

        var newRec = Ext.create('App.model.attendance.DailyTime', {
            AttendanceId: 0,
            EmployeeId: 0,
            SensorId: 0,
            IsManual: true,
            IsActive: true
        });

        // load record to form
        editForm.loadRecord(newRec);

        win.show();
    },
然后将显示我的表单,但某些字段具有如下“0”:

{ name: 'EmployeeId', type: 'int', defaultValue: '', convert: null },

因此,我试图解决问题,但我无法使其正常工作:

我尝试在模型中使用
convert
函数,该函数在0值时返回
'

我还尝试在模型中使用
defaultValue
,但没有成功

我还尝试在创建模型时设置
EmployeeId:“
,但没有成功


应该有我遗漏的东西,非常感谢您的帮助。

有效的解决方案是:

在模型中,设置要具有所需行为的属性,如下所示:

{ name: 'EmployeeId', type: 'int', defaultValue: '', convert: null },
然后,在创建模型时,将属性设置为“未定义”

var newRecord = Ext.create('CustomModel',{
    EmployeeId: undefined
});
然后加载表单:

form.loadRecord(newRecord);
form.updateRecord(newRecord);
提交表格后:

form.loadRecord(newRecord);
form.updateRecord(newRecord);

我已经有一段时间没有热衷于ExtJS开发了,但是我对我们所有的表都有同样的问题,我们为这些表保留了下拉信息。如果您通过id链接它们,当它们尚未设置时,它们总是显示0而不是无值。我最终在模型中将类型设置为字符串,这缓解了我的问题。也许这对你也有用?我的web服务非常宽容返回的数据类型,所以这不是一个大问题,但也许你不是这样?只需发布我找到的解决方案。刚刚删除,它可以工作,但当你试图更改字段的值时,它不会反映在模型中。