如何在 extraParams 存储 extjs 上设置动态值

问题描述

嗨,我在 extjs 上将动态值存储到 extraParams 时遇到问题..

我的情况是当我在这里console时我可以从我的组件中获得价值:

listeners: {
    load: function (store,records,success) {
        console.log(Ext.ComponentQuery.query('comboBox[reference=terminal2]')[0])
    }
}

我从该组件获得了值,但是当我尝试将其传递给 extraParam 时出现错误 undefined..

proxy: {
    type: 'ajax',url: Config.getApi() + 'api/public/index',extraParams: {
        dParams: Ext.ComponentQuery.query('comboBox[reference=terminal2]')[0]
    },},

我收到错误 undefined..

我的完整商店代码

Ext.define('Admin.store.npk.mdm.LayananAlat',{
    extend: 'Ext.data.Store',alias: 'store.layananalat',requires: [
        'Config'
    ],autoLoad: true,proxy: {
        type: 'ajax',actionMethods: {
            read: 'POST'
        },paramsAsJson: true,timeout: 120000,extraParams: {
            dParams: Ext.ComponentQuery.query('comboBox[reference=terminal2]')[0]
        },headers: {
            'token': Ext.util.Cookies.get('Tokens')
        },reader: {
            type: 'json',rootProperty: function (obj) {
                return obj.result
            },totalProperty: function (obj) {
                return obj.count
            }
        }
    },listeners: {
        load: function (store,success) {
            console.log(Ext.ComponentQuery.query('comboBox[reference=terminal2]')[0])
        }
    }
});

或者是否有另一种方法可以将动态值传递给 extjs 中 extraParams 存储中的 proxy

解决方法

您的代理设置将在构建阶段设置,此时您的 UI 很可能未构建,因此您的组件查询无法返回引用的 UI 元素。

关闭 autoLoad 并从存储定义中删除代理部分。然后在可以确定 UI 已经构建好的地方设置代理。例如。在视图的 show/painted 事件中,您可以添加像

这样的代码
   const store = Ext.getStore('layananalat');
   store.setProxy({
        type: 'ajax',url: Config.getApi() + 'api/public/index',actionMethods: {
            read: 'POST'
        },paramsAsJson: true,timeout: 120000,extraParams: {
            dParams: Ext.ComponentQuery.query('combobox[reference=terminal2]')[0]
        },headers: {
            'token': Ext.util.Cookies.get('Tokens')
        },reader: {
            type: 'json',rootProperty: function (obj) {
                return obj.result
            },totalProperty: function (obj) {
                return obj.count
            }
   });
   store.load();

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...