2013-06-12 21 views
0

我會在我的代理api store中放置一個變量(使用crud),但它不起作用。Extjs變量在proxy proxy api store中使用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)]); 
    } 
}); 

回答

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' 
}, 

看到語法高亮的區別?

+0

Sencha Architect在我使用變量的時候格式化類...我的代碼api正好是您的代碼 – VincentDA

+0

好吧,這就解釋了它。我無法相信你沒有看到。那時建築師就會遇到這個問題。不幸的是,我沒有經驗。它會在您輸入代碼後立即格式化您的代碼,或者在稍後的步驟(如代碼生成,我不知道)? – rixo