Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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
通过extjs 5中的模型进行表单验证_Extjs_Extjs5 - Fatal编程技术网

通过extjs 5中的模型进行表单验证

通过extjs 5中的模型进行表单验证,extjs,extjs5,Extjs,Extjs5,我正在探索使用模型验证器进行ExtJS5表单验证。我希望表单显示PersonModel中的错误 这是一个简单的表单,用于创建和保存和Person实例 如何连接模型、模型视图和视图以实现这一点 谢谢 Ext.application({ name: 'Fiddle', launch: function() { Ext.define('PersonModel', { extend: 'Ext.data.Model',

我正在探索使用模型验证器进行ExtJS5表单验证。我希望表单显示PersonModel中的错误

这是一个简单的表单,用于创建和保存和Person实例

如何连接模型、模型视图和视图以实现这一点

谢谢

Ext.application({
    name: 'Fiddle',

    launch: function() {

        Ext.define('PersonModel', {
            extend: 'Ext.data.Model',
            fields: [{
                name: 'fullName',
                type: 'string',
                validators: [{
                    type: 'presence'
                }]
            }]
        });

        Ext.define('PersonViewModel', {
            extend: 'Ext.app.ViewModel'
        });

        // Form should show the required (presence) field validators as errors
        // when create button is clicked since formBind = true
        // I want form to use the model field validators, I don't want to
        // put validators in form
        //
        // How do I hook up view, viewmodel and model for this ????
        //
        Ext.define('PersonFormView', {
            extend: 'Ext.form.Panel',
            modelValidation: true,
            viewModel: {
                type: 'PesonViewModel'
            },
            title: 'Create Person',
            defaultType: 'textfield',
            items: [{
                fieldLabel: 'Full Name',
                name: 'fullName',
                vtype: 'required'
            }],
            buttons: [{
                text: 'Create',
                formBind: true,
                disabled: true,
                handler: function() {
                    // if valid
                    //  create Person model instance and .save()
                }
            }]
        });


        //
        // show form

        Ext.create('PersonFormView', {
            renderTo: Ext.getBody()
        })
    }
});

我是这样想的。如果你知道更好的方法,请告诉我


我花了几天时间试图理解在表单上使用datamodel和viewmodel,但仍然没有得到答案。在本例中,实际上没有使用viewmodel,并且因为我们使用数据绑定,所以没有理由使用GetValue来获取表单数据,