ExtJs6解决添加和修改Form共用一个form的隐藏域的id的取消传值

问题重现:修改不会有问题,id会绑定之前的grid,有具体数字

添加有问题,因为id是空,传的是绑定值的话会显示“类名-1”,从int类型变成了string类型,后台会出错

这是EduQuestionBankForm的代码

/**
 * @author cjy
 * @Date 2018/6/2 15:06.
 */
Ext.define('Admin.view.eduQuestionBank.EduQuestionBankForm', {
    extend: 'Ext.window.Window',
    xtype: 'eduQuestionBankForm',

    title: '题库添加',
    requires: [
        'Admin.view.eduQuestionBank.EduQuestionBankFormController',
        'Ext.form.Panel',
        'Ext.form.field.ComboBox',
        'Ext.form.field.Text',
        'Ext.form.field.TextArea',
        'Ext.layout.container.Fit'
    ],

    layout: 'fit',

    modal: true,
    height: 440,
    width: 500,

    controller: 'eduQuestionBankForm',

    viewModel: {
        links: {
            theEduQuestionBank: {
                type: 'eduQuestionBank.EduQuestionBank',
                create: true
            }
        },
        data: {
            roleComboQueryMode: 'remote'
        }
    },

    items: {
        xtype: 'form',
        id:'dictionaryF',
        modelValidation: true,
        defaults: {
            labelAlign: 'left',
            margin: 10,
            msgTarget: 'side'
        },
        items: [{
            xtype:'hidden',
            name:'id',
            id :'hiddenEduQuestionBankId',
            bind:{
                value:'{theEduQuestionBank.id}'
            }
        },{
            xtype: 'textfield',
            name: 'title',
            allowBlank:false,
            fieldLabel: '题库名称',
            bind: {
                value: '{theEduQuestionBank.title}'
            }
        }, {
            xtype: 'textfield',
            name: 'postType',
            fieldLabel: '对应岗位',
            allowBlank:false,
            bind: '{theEduQuestionBank.postType}'
        }, {
            xtype: 'textfield',
            name: 'createUserId',
            fieldLabel: '创建人',
            allowBlank:false,
            bind: '{theEduQuestionBank.createUserId}'
        }],
        buttons: [{
            text: '确定',
            handler: 'editEduQuestionBank'
        }, {
            text: '取消',
            handler: 'closeEduQuestionBankWindow'
        }]
    }
});

解决方案:

正则判断是否是数字,是数字则找到id或者name的地方,将其禁用,就不会再向后台发送参数了

var reg =  /^\d+$/;
            if (!reg.test(form.form.findField('hiddenEduQuestionBankId').getValue())) {
                form.form.findField('hiddenEduQuestionBankId').setDisabled(true);
            }

猜你喜欢

转载自www.cnblogs.com/Java-Starter/p/9133429.html