douyi6290 2013-06-12 21:05
浏览 38

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

I would put a variable in my proxy api store (using crud) but it not work.

The api config is an object , could you use a variable in object in javascript ?

I use Sencha Architect and he format api...

Do you have a suggest ?

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: '{
    create: UrlPays+'action=create',
    read: UrlPays+'action=read',
    update: UrlPays+'action=update',
    destroy: UrlPays+'action=destroy'
}',
                reader: {
                    type: 'json',
                    root: 'data'
                },
                writer: {
                    type: 'json',
                    root: 'data'
                }
            }
        }, cfg)]);
    }
});
  • 写回答

1条回答 默认 最新

  • dswm97353 2013-06-12 21:19
    关注

    You can use the UrlPays anywhere in your file, since you declared it in the global scope (i.e. outside of any function).

    That should work if you fix this line:

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

    like this:

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

    See the difference in the syntax highlighter?

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料