【问题标题】:Can't resolve "c is not a constructor" error无法解决“c 不是构造函数”错误
【发布时间】:2011-12-10 00:58:00
【问题描述】:

我正在尝试使用 ExtJS 构建一个非常基本的“概念验证”应用程序,但我遇到了非常困难的情况。

我想要的只是两个网格从远程 JSON 文件中获取数据,但无论我做什么,我都会不断收到主题中的错误。

这是我的简单代码:

app.js:

Ext.Loader.setConfig({enabled:true});

Ext.application({
    name: 'GeoSniffer',
    autoCreateViewport: true,
    models: ['Location', 'Client'],    
    stores: ['Locations', 'Clients'],
});

Viewport.js

Ext.define('GeoSniffer.view.Viewport', {
    extend: 'Ext.container.Viewport',
    layout: 'fit',

    requires: [
        'GeoSniffer.view.ClientsList',
        'GeoSniffer.view.LocationsList'
    ],

    initComponent: function() {
        this.items = {
            layout: {
                type: 'hbox',
                align: 'stretch'
            },
            items: [{
                width: 250,
                xtype: 'panel',
                id: 'west-region',
                layout: {
                    type: 'vbox',
                    align: 'stretch'
                },
                items: [{
                    xtype: 'locationslist',
                    flex: 1
                },{
                    xtype: 'clientslist',
                    flex: 1             
                }]
            }]
        };

        this.callParent();
    }
});

Client.js:

Ext.define('GeoSniffer.model.client', {
    extend: 'Ext.data.Model',
    fields: [
        'ip', 
        'packetsCount', 
        'firstPacketUsec', 
        'latestPacketUsec', 
        'location', 
        'sessionsArr', 
        'currentSession'
    ]
});

Location.js:

Ext.define('GeoSniffer.model.Location', {
    extend: 'Ext.data.Model',
    fields: [
        'countryCode', 
        'countryName', 
        'region', 
        'city', 
        'postalCode', 
        'latitude', 
        'longitude', 
        'dma_code', 
        'area_code', 
        'metro_code', 
        'packetsCount', 
        'sessionsArr', 
        'currentSession', 
        'clients'
    ]
});

Clients.js:

Ext.define('GeoSniffer.store.Clients', {
    extend: 'Ext.data.Store',
    requires: 'GeoSniffer.model.Client',
    model: 'GeoSniffer.model.Client',
    autoLoad: false,
    proxy: {
        type: 'ajax',
        url: 'data/clients.json',
        reader: {
            type: 'json',
            root: 'clients_list'
        }
    }
});

Locations.js:

Ext.define('GeoSniffer.store.Locations', {
    extend: 'Ext.data.Store',
    requires: 'GeoSniffer.model.Location',
    model: 'GeoSniffer.model.Location',
    autoLoad: false,
    proxy: {
        type: 'ajax',
        url: 'data/locations.json',
        reader: {
            type: 'json',
            root: 'locations_list'
        }
    }
});

ClientsList.js:

Ext.define('GeoSbiffer.view.ClientsList', {
    extend: 'Ext.grid.Panel',
    alias: 'widget.clientslist',

    store: 'Clients',
    title: 'Clients',
    hideHeaders: true,

    initComponent: function() {
        this.columns = [
            {
                dataIndex: 'ip',
            },
            {
                dataIndex: 'packetsCount',          
            }

        ];

        this.callParent();
    }
});

LocationsList.js:

Ext.define('GeoSbiffer.view.LocationsList', {
    extend: 'Ext.grid.Panel',
    alias: 'widget.locationslist',

    store: 'Locations',
    title: 'Locations',
    hideHeaders: true,

    initComponent: function() {
        this.columns = [{
            dataIndex: 'countryName',
            flex: 1
            },{
            dataIndex: 'city',
            flex: 1             
            }

        ];

        this.callParent();
    }
});

clients.json

{
    "sessions_arr": [ 7, 0, 6, 1, 6, 8, 2, 39, 0, 5, 12, 8],
    "clients_list": [
      {
        "ip": "82.166.201.153",
        "packetsCount": 1,
        "firstPacketUsec": 211474,
        "latestPacketUsec": 211474,
        "location": {
          "countryCode": "IL",
          "countryName": "Israel",
          "region": "unknown",
          "city": "unknown",
          "latitude": 31.5,
          "longitude": 34.75,
          "dma_code": 0,
          "area_code": 0,
          "metro_code": 0,
          "packetsCount": 0,
          "currentSession": 0,
          "clients": []
        },
        "sessionsArr": [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        "currentSession": 1
      }
    ],
    "status": {
      "executionResult": "OK",
      "isSnifferActive": false,
      "servletInfo": ""
    }
}

locations.json

{
    "sessions_arr": [ 7, 0, 6, 1, 6, 8, 2, 39, 0, 5, 12, 8],
    "locations_list": [
      {
        "countryCode": "US",
        "countryName": "United States",
        "region": "CA",
        "city": "Palo Alto",
        "postalCode": "94304",
        "latitude": 37.376205,
        "longitude": -122.1826,
        "dma_code": 807,
        "area_code": 650,
        "metro_code": 807,
        "packetsCount": 2,
        "sessionsArr": [ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        "currentSession": 0,
        "clients": [
          {
            "ip": "69.171.242.14",
            "packetsCount": 2,
            "firstPacketUsec": 368942,
            "latestPacketUsec": 369060,
            "sessionsArr": [ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            "currentSession": 0
          }
        ]
      }
    ],
    "status": {
      "executionResult": "OK",
      "isSnifferActive": false,
      "servletInfo": ""
    }
}

尝试通过堆栈跟踪使用 Firebug 进行调试没有提供任何有用的信息。

我错过了什么??


代码失败的地方:

【问题讨论】:

  • 你能解决这个错误,然后按照堆栈跟踪查看c 的来源吗?
  • @JamesClark:我在我的问题中添加了调用堆栈和断线的屏幕截图...
  • 它正在尝试实例化一个 Ext 类。我认为答案将在alias 方法中,堆栈跟踪中有两个条目。它可能会尝试在那里解决一些 xtype,这将有助于诊断的下一步。

标签: extjs extjs4 extjs-mvc


【解决方案1】:

使用加载程序时,请确保您使用ext-all-dev.js(或ext-dev.js)运行而不是-debug-dev 将报告加载程序错误,但 -debug 不会。随着应用程序的增长,这类问题很难追踪,但开发人员会立即报告(在您的控制台中)。

这个花絮我只见过一次,但它为我节省了几天的调试时间。

【讨论】:

  • +1 非常感谢!最后我知道了开发文件的用途。没人告诉你。追踪此类错误的最佳提示...
  • 我不会回避这个评论,绝对+1!知道这个区别很重要,它可以节省大量的调试时间!
  • @david-kanarek 啊,我下载了 ExtJS 5,我得到了 ext-all, ext-debug ext-rtl 但没有 ext-dev ! ?对这个新版本有什么想法吗?
  • 对不起,我已经有一段时间没有使用 EXT 了。我会尝试使用所有不同的版本,看看是否有任何在控制台中报告错误。你也可以查看 Sencha 的文档,看看他们是否做了任何事情来让这个问题更容易找到。
【解决方案2】:

我重新报告了这个错误,我发现 GeoSniffer.store.Clients 因为你的 client.js 文件中有错字。有GeoSniffer.model.client 而不是GeoSniffer.model.Client。 *List 文件中还使用了GeoSbiffer 命名空间。

【讨论】:

  • 猜猜他“搞砸了”它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-11-02
  • 1970-01-01
  • 2020-05-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-06
相关资源
最近更新 更多