【问题标题】:ExtJS Store Not Loading From ProxyExtJS 存储未从代理加载
【发布时间】:2014-03-27 20:42:11
【问题描述】:

我的代码如下(如果对你有帮助,我可以发布更多!):

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

控制台在执行上面的行时给了我这个:

[Ext.Loader] 同步加载'CountrySpecific';考虑添加 Ext.onReady 上方的 Ext.require('CountrySpecific')

ext-dev.js:8894 获取 [localhost]/extjs/CountrySpecific.js?_dc=1395952634289 404(不是 找到)

ext-dev.js:10587 未捕获的错误:[Ext.Loader] 加载失败 通过 XHR 同步:'CountrySpecific.js';请确认 文件已存在。 XHR 状态码: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.' }}

    ]
});

【问题讨论】:

  • 您确定模型正在加载到商店定义所在的文件中吗?尝试更改型号名称并检查错误是否仍然相同。顺便说一句,您在哪里创建商店?我看到了你的定义,但我似乎找不到任何 Ext.create('RateManagement.store.CountrySpecificStore') 或类似的东西。
  • 我添加了更多代码来显示我在哪里使用商店和模型等等。这是否有助于深入了解这个问题?
  • 你能提供一个小提琴吗?我不确定要不要像你一样设置商店,你以前做过吗?改用Ext.create('yourstore') 试试
  • 我以前做过,它工作正常,它通过访问代理从我的数据库中加载我的所有记录;但是,我的问题是当我使用Ext.data.StoreManager.get("CountrySpecificStore") 时它加载了错误的代理。我真的不知道如何为 extjs 添加小提琴。
  • Sencha fiddle 是这样做的好地方fiddle.sencha.com/#home:P

标签: javascript extjs


【解决方案1】:

您似乎正在使用 StoreManager 获取一个之前没有注册过的商店,所以他尝试动态加载定义。

由于他得到的唯一信息是“CountrySpecificStore”,他试图在 ExtJS 目录中找到这个类。

你必须要求调用Ext.data.StoreManager.get("CountrySpecificStore")的类中的store类

【讨论】:

  • 我添加了更多代码来显示我正在尝试做的事情。我不确定如何在调用商店经理的类中要求商店类。请给我看看好吗?
【解决方案2】:

我的问题是我需要像这样声明我的模型变量:

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

然后,我能够简单地:

var store = myGrid.getStore();

【讨论】:

    猜你喜欢
    • 2015-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-22
    • 2013-05-24
    • 2011-08-17
    • 2015-04-18
    • 1970-01-01
    相关资源
    最近更新 更多