如何使用rest代理创建用于数据存储的静态参数

如何使用rest代理创建用于数据存储的静态参数,rest,extjs,global-variables,loader,Rest,Extjs,Global Variables,Loader,我有一个ExtJS 5.1.2应用程序,在整个应用程序中使用了一组在app_dir/app/Application.js中定义的全局配置参数,如下所示: launch: function () { Ext.Loader.setConfig({enabled: true}); // Static parameters cardioCatalogQT.config = { mode: 'test', // switch to control use of

我有一个ExtJS 5.1.2应用程序,在整个应用程序中使用了一组在app_dir/app/Application.js中定义的全局配置参数,如下所示:

launch: function () {
    Ext.Loader.setConfig({enabled: true});

    // Static parameters
    cardioCatalogQT.config = {

        mode: 'test', // switch to control use of staging or production server
        //protocol: 'https://',
        protocol: 'http://',
        //host: 'production_server',
        //host: 'test_server,
        host: '127.0.0.1:5000',
        apiGetQ: '/get_query/',
        //apiGetQ: '/api/get_query/',
        apiWriteQ: '/remote_query_put',
        apiReadQ: '/remote_query_get',
        //apiMedsMenu: '/api/meds',
        //apiMedsMenu: '/meds',
        remove: 'none'
    };

    // TODO - Launch the application

    Ext.onReady(function () {


    });        
} 
这样,在Ajax调用中,我只有一个地方可以更改组成
url
的参数,(在本例中是
protocol
host
apiGetQ
,例如,允许mr设置
url=cardioCatalogQT.config.protocol+cardioCatalogQT.config.host+cardioCatalogQT.config.apiGetQ)
,在一个地方从开发->测试->生产更改服务器地址,而不必在整个应用程序中查找所有引用

但是,由于ExtJs的加载方式,我无法在使用rest代理的数据存储中使用这些配置参数,因为这些存储似乎在Ext.Loader中的项之前加载

例如,我有以下商店:

Ext.define('cardioCatalogQT.store.Diagnoses', {
    extend: 'Ext.data.Store',
    alias: 'store.Diagnoses',
    config:{
        model: 'cardioCatalogQT.model.Diagnosis',
        storeId: 'Diagnoses',
        autoLoad: true,

        proxy: {
            type: 'rest',
            url: 'http://127.0.0.1:5000/menu/diagnoses',
            //url: 'http://test_server/menu/diagnoses',
            //url: 'https://prod_server/api/menu/diagnoses',
            reader: {
                type: 'json',
                rootProperty: 'menu_test'
            }
        }
    }
});
因此,例如,当我从测试环境更改为开发环境时,我必须在具有rest代理的n个存储中显式更改url的n个不同引用


有没有办法定义一个配置对象,这样我就可以将它用于这些存储?我查看了一些预加载程序的示例,但似乎没有为全局配置对象记录任何用例,我也曾尝试在预加载程序中实现loadmask,但它确实与我的应用程序的行为有关。

我们遇到了类似的问题,因此,我们将我们的全局
ConnectionSettings
对象放入index.html中Ext之前的脚本标记中

<script type="text/javascript">
ConnectionSettings = {
    ...
    ...
};
</script>
<!-- The line below must be kept intact for Sencha Cmd to build your application -->
<script id="microloader" ...

连接设置={
...
...
};

我们也有类似的问题,所以我们将全局
ConnectionSettings
对象放在index.html中的脚本标记中,在Ext之前

<script type="text/javascript">
ConnectionSettings = {
    ...
    ...
};
</script>
<!-- The line below must be kept intact for Sencha Cmd to build your application -->
<script id="microloader" ...

连接设置={
...
...
};

我过去喜欢@Alexander propose,但我更喜欢单身方式。更像ExtJs/MVC。 最后,我分享我的版本:

/**
 * @class
 */
Ext.define("MyApp.config.Config", {
    alternateClassName: [
        'MyApp.config'
    ],
    singleton: true,

    constant: {

        // ... whatever constant you need to put here

    },

    constructor: function() {
        var constant = this.constant;

        //
        // here, if you need to process some stuff
        // for example calculate some constant
        // which depend of other constant
        //


        return constant;
    }
});
在你的应用程序中需要

// Be sure to require your class prior
// to your app classes
Ext.define('MyApp.Application', {
    extend: 'Ext.app.Application',

    requires: [
            'Ext.app.*',
            // ext stuff ...
            'MyApp.config.Config',
            // myApp stuff ...
    ]

    // ...

});
用法示例:

Ext.define('MyApp.store.MyStore', {
    // ...

    proxy: {
        type: 'rest',
        url: MyApp.config.remoteUrl
    }
})

我过去喜欢@Alexander propose,但我更喜欢单身方式。更像ExtJs/MVC。 最后,我分享我的版本:

/**
 * @class
 */
Ext.define("MyApp.config.Config", {
    alternateClassName: [
        'MyApp.config'
    ],
    singleton: true,

    constant: {

        // ... whatever constant you need to put here

    },

    constructor: function() {
        var constant = this.constant;

        //
        // here, if you need to process some stuff
        // for example calculate some constant
        // which depend of other constant
        //


        return constant;
    }
});
在你的应用程序中需要

// Be sure to require your class prior
// to your app classes
Ext.define('MyApp.Application', {
    extend: 'Ext.app.Application',

    requires: [
            'Ext.app.*',
            // ext stuff ...
            'MyApp.config.Config',
            // myApp stuff ...
    ]

    // ...

});
用法示例:

Ext.define('MyApp.store.MyStore', {
    // ...

    proxy: {
        type: 'rest',
        url: MyApp.config.remoteUrl
    }
})

我也非常喜欢这种单身方式。在目录结构中,这个目录放在哪里(是MyApp_dir/app/config目录)?是的,没错!例如,在我的应用程序中,我有多个配置文件。@psycho,@alexander我也在使用这个策略singleton配置类,但只是为了创建讨论,您对访问prototype(如果我们不需要处理常量上的自定义内容)有何看法:
Admin.view.myview.Mymodule.prototype.myconstant
@jamesjara,为什么不呢,它也有用!但是我发现它不那么优雅,它更详细(键入所有路径),并且出于某种原因,如果您将文件移动到另一个文件夹中,并且希望保持ExtJs的名称空间一致,则需要更改对常量的所有引用。。。我真的更喜欢带有
alternateClassName
选项的单例方式!我也非常喜欢这种单身方式。在目录结构中,这个目录放在哪里(是MyApp_dir/app/config目录)?是的,没错!例如,在我的应用程序中,我有多个配置文件。@psycho,@alexander我也在使用这个策略singleton配置类,但只是为了创建讨论,您对访问prototype(如果我们不需要处理常量上的自定义内容)有何看法:
Admin.view.myview.Mymodule.prototype.myconstant
@jamesjara,为什么不呢,它也有用!但是我发现它不那么优雅,它更详细(键入所有路径),并且出于某种原因,如果您将文件移动到另一个文件夹中,并且希望保持ExtJs的名称空间一致,则需要更改对常量的所有引用。。。我真的更喜欢带有
alternateClassName
选项的单例方式!