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

时间:2013-06-12 21:05:15

标签: php javascript url extjs crud

我会在我的代理api商店中添加一个变量(使用crud),但它不起作用。

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

我使用Sencha Architect并且他格式化api ...

你有建议吗?

我的基地商店:

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)]);
    }
});

我在api代理中使用变量的模型

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)]);
    }
});

1 个答案:

答案 0 :(得分:0)

您可以在文件中的任何位置使用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'
},

查看语法高亮显示器的区别?