2014-03-27 100 views
1

我的代碼如下(我可以發佈更多的,如果它會幫助你幫幫我吧!):ExtJS的商店不加載從代理

//var store = myGrid.getStore(); 
var store = Ext.data.StoreManager.get("CountrySpecificStore") 
console.log(store); 

控制檯讓我在上面的行執行此:

[Ext.Loader] Synchronously loading 'CountrySpecific'; consider adding Ext.require('CountrySpecific') above Ext.onReady

ext-dev.js:8894 GET [localhost]/extjs/CountrySpecific.js?_dc=1395952634289 404 (Not Found)

ext-dev.js:10587 Uncaught Error: [Ext.Loader] Failed loading synchronously via XHR: 'CountrySpecific.js'; please verify that the file exists. XHR status code: 404 ext-dev.js:10857

相反的http://localhost/extjs/CountrySpecific.js?_dc=1395952634289應該叫我的代理其定義爲:

Ext.define('RateManagement.store.CountrySpecificStore', { 
    extend: 'Ext.data.Store', 
    model: 'RateManagement.model.CountrySpecific', 
    proxy: { 
     type: 'rest', 
     format: 'json', 
     url: '/intake/sap/rates/CountrySpecific' 
    }, 
    autoSync: true, 
    autoLoad: true 
}); 

我怎樣才能撥打電話http://localhost/intake/sap/rates/CountrySpecific

注意:我正在使用ExtJS 4.2.1。

編輯:這裏是我的網格,在那裏我使用的商店使用:

Ext.define('RateManagement.view.Grids.CountrySpecificGrid', { 
    extend: 'Ext.grid.Panel', 
    requires:['Ext.ux.CheckColumn'], 
    xtype: 'CountrySpecificGrid', 
    store: 'RateManagement.store.CountrySpecificStore', 
    plugins: [{ 
     clicksToMoveEditor: 1, 
     autoCancel: false, 
     ptype: 'rowediting', 
     pluginId: 'rowediting' 
    }], 
    tbar: [{ 
      text: 'Add Rate', 
      handler: function(button) { 
       var myGrid = button.up('grid'); 
       //console.log(myGrid); 
       var myPlugin = myGrid.getPlugin('rowediting'); 
       myPlugin.cancelEdit(); 

       var r = Ext.create('CountrySpecific', { 
        id: '', 
        hostCountryId: '', 
        hostCountry: '', 
        rate: 0, 
        currencyId: '', 
        rateTypeId: '', 
        frequencyCode: '', 
        perFamilyMember: '', 
        familySize: 0 
       }); 

       //var store = myGrid.getStore(); 
       var store = Ext.data.StoreManager.get("CountrySpecificStore") 
       console.log(store); 

       // todo: create guid and add to store 
       store.insert(0, r); 
       myPlugin.startEdit(0, 0); 
      } 
     }], 
    features: [{ 
     ftype: 'filters', 
     encode: false, 
     local: true, 
     filters: [ 
      { type: 'string', dataIndex:'hostCountry' }, 
      { type: 'numeric', dataIndex:'rate' }, 
      { type: 'string', dataIndex:'currencyId' } 

     ] 
    }], 
    columns: [ 
     {text: 'Host Country', dataIndex: 'hostCountry', width:150}, 
     {text: 'Rate', dataIndex: 'rate', xtype: 'numbercolumn', 
      editor: { xtype: 'numberfield', allowBlank: false, minValue: 0, blankText: 'Rate is required.', invalidText: 'Rate must be positive.' }}, 
     {text: 'Rate Currency', dataIndex: 'currencyId', xtype: 'currency-column' }, 
     {text: 'Frequency', xtype: 'rate-type-column' }, 
     {text: 'PerFamilyMember', dataIndex: 'perFamilyMember', xtype: 'checkcolumn', 
      editor: {xtype: 'checkbox',cls: 'x-grid-checkheader-editor'}}, 
     {text: 'Family Size', dataIndex: 'familySize', 
      editor: { xtype: 'numberfield', minValue: 0, invalidText: 'Family Size must be positive.' }} 

    ] 
}); 
+1

您確定模型正在加載到商店定義所在的文件嗎?嘗試更改型號名稱並檢查錯誤是否仍然相同。順便說一下,你在哪裏創建商店?我看到你的定義,但我似乎無法找到任何'Ext.create('RateManagement.store.CountrySpecificStore')'或類似的東西。 – lascort

+0

我添加了更多的代碼,顯示我在哪裏使用商店和模型等等。這是否有助於深入瞭解這個問題? – user1477388

+0

你能提供一個小提琴嗎?我不確定如何設置店鋪,你以前是否會這樣做?嘗試用'Ext.create('yourstore')'而不是 – lascort

回答

1

好像你正在使用的StoreManager拿到店裏,尚未註冊之前,所以他試圖動態加載定義。

由於他得到的唯一信息是「CountrySpecificStore」,他試圖在ExtJS目錄中找到這個類。

您有權要求在調用Ext.data.StoreManager.get("CountrySpecificStore")

+0

我添加了更多的代碼,顯示我正在嘗試做什麼。我不確定如何在調用商店經理的類中需要商店類。你能告訴我嗎? – user1477388

0

我的問題是我需要聲明我的模型變量這樣的類商店類:

var r = Ext.create('RateManagement.model.CountrySpecific', { 
    id: '', 
    hostCountryId: '', 
    hostCountry: '', 
    rate: 0, 
    currencyId: '', 
    rateTypeId: '', 
    frequencyCode: '', 
    perFamilyMember: '', 
    familySize: 0 
}); 

然後,我就能夠簡單:

var store = myGrid.getStore();