ExtJs v4.2.1.883 - 没有模型创建的Ext.data.Store。该名称与有效模型不对应

时间:2013-06-10 16:39:35

标签: javascript model-view-controller extjs

使用以下代码片段为网格生成模型和存储,我将收到错误:

[W] Ext.data.Store created with no model. The name 'MyCompany.model.SomeModel' does not correspond to a valid model. ext-all-dev.js:12297
Uncaught TypeError: Cannot read property 'prototype' of undefined ext-all-dev.js:61224
    Ext.define.readRecords ext-all-dev.js:61224
    Base.implement.callParent ext-all-dev.js:6949
    Ext.define.readRecords ext-all-dev.js:61905
    Ext.define.read ext-all-dev.js:61195
    Ext.define.read ext-all-dev.js:102530
    Ext.define.load ext-all-dev.js:64125
    Base.implement.callParent ext-all-dev.js:6949
    Ext.define.load ext-all-dev.js:104696
    Ext.define.read ext-all-dev.js:63754
    Ext.define.constructor ext-all-dev.js:103732
    constructor ext-all-dev.js:8158
    (anonymous function)
    Ext.ClassManager.instantiate ext-all-dev.js:8908
    (anonymous function) ext-all-dev.js:3385
    (anonymous function) UserTraffic:401
    (anonymous function) ext-all-dev.js:16064
    fire ext-all-dev.js:16019
    Ext.apply.readyEvent.readyEvent.fire ext-all-dev.js:16277
    Ext.apply.fireReadyEvent ext-all-dev.js:16377
    (anonymous function)

代码:

Ext.onReady(function()
{
    var rawdata = [["2013-05-10T00:00:00",152,152,1643],["2013-05-11T00:00:00",5292,5292,51794] /* ... */ ];

    var model = Ext.define('MyCompany.model.SomeModel', {
        "fields": [
            {
                "dateFormat": "c",
                "mapping": 0,
                "name": "date",
                "type": "date"
            },
            {
                "mapping": 1,
                "name": "ActiveVisits",
                "type": "int"
            },
            {
                "mapping": 2,
                "name": "ActiveVisits",
                "type": "int"
            },
            {
                "mapping": 3,
                "name": "PageViews",
                "type": "int"
            }
        ],
        "extends": "Ext.data.Model"
    });


    var store = Ext.create('Ext.data.Store', {
        "data": rawdata,
        "proxy": { "type": "memory" },
        "id": "MyCompany.store.SomeModel",
        "sorters": [
            { "property": "date", "direction": "DESC" }
        ],
        "model": 'MyCompany.model.SomeModel',
        "requires": [ "MyCompany.model.SomeModel" ]
    });

    // ... clipped

});

我很痛苦地看到我所缺少的东西,提前感谢您的帮助!

我正在使用ExtJs v4.2.1.883

1 个答案:

答案 0 :(得分:1)

你的数字反应过于严重。

您在模型定义中输入了extends而不是extendextends是Javascript的保留(但未使用)关键字,因此Ext必须使用较不标准的名称...

仅供参考,您不需要在引号中包含对象属性名称,除非它们包含特殊字符:

{
    extend: '...' // that's ok
}