Extjs6.2现代工具包 - 扩展文本框

时间:2018-03-08 00:40:22

标签: extjs extjs6-modern extjs6.2

我还在学习EXTJs,我试图扩展组件之一。以下是我的例子:

xtype: 'fieldset',
        margin: 10,
        bind: '{workOrders}',
        title: 'Dispatch Information',
        items: [
            {   
                id: 'Tag',
                xtype: 'customtextfield',
                name: 'Tag',
                label: 'Tag',
                bind: '{Tag}',
                labelAlign: 'top'
            },

我想调用一个控制器方法来验证用户是否有权查看此字段并相应地执行下一步操作。我想在导航到视图时发生这种验证 我在View中使用了这个自定义字段:

{{1}}

但是initComponent永远不会被触发。 即使在我的商店加载之前,初始化也很快就会被触发。如何正确扩展此控件?

1 个答案:

答案 0 :(得分:0)

在现代的ExtJS 6中,textfield没有initComponent个事件。 initComponent事件有  在textfield的经典中。

要调用controller中的活动,您需要创建controller并定义view

FIDDLE 中,我使用formViewControllertextfieldViewModel创建了一个演示版。我希望这有助于/指导您实现您的要求。

有关详细信息,请参阅ExtJS Docs

CODE SNIPPET

Ext.application({
    name: 'Fiddle',

    launch: function () {

        //Define the cutsometext from extending {Ext.field.Text}
        Ext.define('CustomText', {
            extend: 'Ext.field.Text',
            xtype: 'customtext',
            labelAlign: 'top',
            listeners: {
                initialize: 'onInitializeCutsomText'
            }
        });

        Ext.define('FormModel', {
            extend: 'Ext.app.ViewModel',
            alias: 'viewmodel.formmodel',

            data: {
                user: {
                    firstName: 'Narendra',
                    lastName: 'Jadhav',
                    email: 'narendrajadhav105@gmail.com'
                },
                permissionCng: {
                    firstName: false,
                    lastName: false,
                    email: true,
                    isAdmin: false
                }
            }

        });
        //Define the FormController from extending {Ext.app.ViewController}
        Ext.define('FormController', {
            extend: 'Ext.app.ViewController',
            alias: 'controller.formctn',

            onInitializeCutsomText: function (textfield) {
                var permissionCng = this.getViewModel().get('permissionCng');
                // Here is just basic example for disabled textfield on initialize event.
                //In your case you can put your requirement.
                textfield.setDisabled(permissionCng[textfield.getName()]);
            }
        });

        //Creating form
        Ext.create('Ext.form.Panel', {
            fullscreen: true,
            viewModel: {
                type: 'formmodel'
            },
            controller: 'formctn',
            items: [{
                xtype: 'fieldset',
                title: 'Personal Info',
                defaults: {
                    xtype: 'customtext' //Here I am using {customtext}
                },
                items: [{
                    label: 'First Name',
                    name: 'firstName',
                    bind: {
                        value: '{user.firstName}',
                        //You can also use like property
                        //hidden:'{permissionCng.firstName}'
                    }
                }, {
                    label: 'Last Name',
                    name: 'lastName',
                    bind: {
                        value: '{user.lastName}',
                        //You can also use like property
                        //hidden:'{permissionCng.firstName}'
                    }
                }, {
                    label: 'Email Id',
                    name: 'email',
                    bind: {
                        value: '{user.email}',
                        //You can also use like property
                        //hidden:'{permissionCng.firstName}'
                    }
                }, {
                    label: 'Admin Name',
                    name: 'isAdmin',
                    bind: {
                        value: '{user.isAdmin}',
                        //You can also use like property
                        hidden: '{!permissionCng.isAdmin}'
                    }
                }]
            }]
        });
    }
});