【问题标题】:How to get value from reference in ExtJS如何从 ExtJS 中的引用中获取价值
【发布时间】:2021-01-18 10:54:23
【问题描述】:

我的 ext js 有问题,我想在我的商店中使用引用从我的字段中获取价值,但是当我 console.log 时出现错误 lookupReference is not a function。

我的表格

items: [
    {
        xtype: 'combobox',
        name: 'REC_TERMINAL_CODE_2',

        fieldLabel: 'Terminal 2',
        emptyText : 'Terminal',
        reference: 'terminal2'
    },
    {
        xtype: 'combobox',
        name: 'REC_TERMINAL_CODE',

        fieldLabel: 'Terminal',
        emptyText : 'Terminal',

        store: {
            type: 'terminal'
        },

        displayField: 'terminal_name',
        valueField: 'terminal_code',
        value: 'T01',
        
        minChars: 3,
        queryParam: 'q',
        queryMode: 'remote',

        editable: false,
        allowBlank: false,

        fieldStyle: 'text-transform:uppercase',

        afterLabelTextTpl: [
        '<span style="color:red;font-weight:bold" data-qtip="Required"> *</span>'
        ],

        flex: 1
    },
]

在我的终端存储文件中

listeners: {
    load: function (store, records, success) {
        console.log(this.lookupReference('terminal2'))
        if (!success) {
            Ext.Msg.confirm('Status Error', 'This connection failed, reload ?',
                function (choice) {
                    if (choice === 'yes') {
                        window.location.reload();
                    }
                }
            );
        }
    }
}

【问题讨论】:

    标签: javascript extjs sencha-architect


    【解决方案1】:

    存储不是组件,因此您可以使用 getReferenceHolder()。您可以使用通用的 Ext.ComponentQuery.query('combobox[reference=terminal2]')[0]

    这将返回一个适合查询的组件数组。

    【讨论】:

      【解决方案2】:

      首先,您的监听器中的this 不是指组合框等组件。它可能指的是存储实例或控制器类。尝试确保您访问组件实例。可以通过登录到控制台来确定,ExtJs 中的默认组件具有 xtype 属性,例如组合框、容器等。一旦您可以访问组件(父组件),您就可以使用函数找到它的子组件,该子组件具有命名引用。

      其次,根据他们的docs,你可以使用parentComponent.getReferences()['PARTICULAR_REFERENCE_NAME']函数通过它的引用获取组件。 parentComponent 可以是表单、容器等。不知道你用的是什么版本的 ExtJS,getReferences 函数可能在低版本中不存在。

      【讨论】:

      • 我收到错误parentComponent not found 或类似的东西..
      • parentComponent 表示通过选择一个组件来启动的变量,例如:``` var parentComponent = Ext.getCmp('YourParentComponentId'); ``` 所以它之前是不存在的,你必须先声明并启动它。所以你可以在代码的下一行使用它。
      【解决方案3】:

      如果您想获取 ExtJS 组件,如上例所示。
      然后你将referenceHolder属性启用为true。

      请参考此链接,例如:
      Fetching ExtJs Component in View

      此属性使视图成为组件的参考持有者 更多详情
      请参考文档链接:
      Sencha docs ReferenceHolder

      【讨论】:

        猜你喜欢
        • 2017-02-13
        • 1970-01-01
        • 2011-12-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-01
        • 2018-04-07
        • 2021-12-26
        相关资源
        最近更新 更多