使用crud存储代理api中的Extjs变量

Extjs variable in proxy api store using crud

本文关键字:中的 Extjs 变量 api 代理 crud 存储 使用      更新时间:2023-09-26

我将在我的代理api存储中放置一个变量(使用crud),但它不起作用。

api配置是一个对象,你能在javascript的对象中使用变量吗?

我使用Sencha Architect和格式api…

你有什么建议吗?

My base store:

Ext.define('ModuleGestion.store.Pays', {
    extend: 'Ext.data.Store',
    requires: [
        'ModuleGestion.model.Pays'
    ],
    constructor: function(cfg) {
        var me = this;
        cfg = cfg || {};
        me.callParent([Ext.apply({
            autoLoad: true,
            model: 'ModuleGestion.model.Pays',
            storeId: 'StorePays',
            proxy: {
                type: 'ajax',
                api: {
                    create: 'http://visual04/ModuleGestion/php/Pays.php?action=create',
                    read: 'http://visual04/ModuleGestion/php/Pays.php?action=read',
                    update: 'http://visual04/ModuleGestion/php/Pays.php?action=update',
                    destroy: 'http://visual04/ModuleGestion/php/Pays.php?action=destroy'
                },
                reader: {
                    type: 'json',
                    root: 'data'
                },
                writer: {
                    type: 'json',
                    root: 'data'
                }
            }
        }, cfg)]);
    }
});

My model with variable in api proxy

var Url = 'http://visual04/ModuleGestion/php/';
var UrlPays = Url+'Pays.php';
Ext.define('ModuleGestion.store.Pays', {
        extend: 'Ext.data.Store',
    requires: [
        'ModuleGestion.model.Pays'
    ],
    constructor: function(cfg) {
        var me = this;
        cfg = cfg || {};
        me.callParent([Ext.apply({
            autoLoad: true,
            model: 'ModuleGestion.model.Pays',
            storeId: 'StorePays',
            proxy: {
                type: 'ajax',
                api: '{'r'n    create: UrlPays+'action=create','r'n    read: UrlPays+'action=read','r'n    update: UrlPays+'action=update','r'n    destroy: UrlPays+'action=destroy''r'n}',
                reader: {
                    type: 'json',
                    root: 'data'
                },
                writer: {
                    type: 'json',
                    root: 'data'
                }
            }
        }, cfg)]);
    }
});

你可以在文件的任何地方使用UrlPays,因为你在全局范围内声明了它(即在任何函数之外)。

如果你修改这一行,应该可以工作:

api: '{'r'n    create: UrlPays+'action=create','r'n    read: UrlPays+'action=read','r'n    update: UrlPays+'action=update','r'n    destroy: UrlPays+'action=destroy''r'n}',

:

api: {
    create: UrlPays + 'action=create',
    read: UrlPays + 'action=read',
    update: UrlPays + 'action=update',
    destroy: UrlPays + 'action=destroy'
},

看到语法高亮的区别了吗?