0

我正在尝试将 JSON 字符串加载到 EXTJS 网格中。我得到的错误Uncaught TypeError: Cannot read property 'prototype' of undefined来自 ext-all-debug.js。

这是我的js文件代码。

$(document).ready(function () {
    var store = new Ext.data.Store(
    {
        proxy: new Ext.data.HttpProxy(
            {
                url: 'http://localhost:3197/Home/GetSecondaryOfferings'
            }),
        reader: new Ext.data.JsonReader(
            {
                root: 'items',
                totalProperty: 'totalCount',
                id: 'id',
                fields: [{name:'CUSIP', mapping: 'CUSIP'},'DESCRIPTION','COUPONRATE','ASKPRICE']
            })
    });
    store.load();

  var grid = new Ext.grid.GridPanel({
     store: store,
     columns: [
        { header: 'CUSIP', dataIndex: 'CUSIP'},
        { header: 'Description', dataIndex: 'DESCRIPTION', width: 100 },
        { header: 'COUPONRATE', dataIndex: 'COUPONRATE', width: 100 },
        { header: 'ASKPRICE', dataIndex: 'ASKPRICE', width: 100 }
     ],
     renderTo: 'example-grid2',
     width: 1000,
     autoHeight: true,
     title: 'Employees'
  });   
});

这是返回的 JSON 文件的示例,它确实被返回了......

{"items":[{"CUSIP":"989701AL1","DESCRIPTION":"ZIONS BANCORPORATIONSB NT 5.65000% 05/15/2014","COUPONRATE":"  5.650","ASKPRICE":"    104.450"}],"totalCount":3316}

为了更好地衡量,这里是 .cshtml 文件。我正在使用 ASP MVC。

@{
    ViewBag.Title = "About Us";
}

<h2>About</h2>
<p></p>
  @section JavaScript
  {
     <link href ="@Url.Content("~/Content/resources/css/ext-all.css")" rel="Stylesheet" type="text/css"/>
 <link rel="stylesheet" type="text/css" href=@Url.Content("~/Content/resources/css/ext-all.css") /> 
    <link rel="stylesheet" type="text/css" href=@Url.Content("~/Content/examples/shared/example.css") /> 
    <script type="text/javascript" src=@Url.Content("~/Content/bootstrap.js")></script> 


      <script type="text/javascript" src=@Url.Content("~/Content/examples/grid/FIO8472-JSON.js")></script> 
     }
<div id="example-grid"></div> 
<div id="example-grid2"></div> 

任何帮助表示赞赏。

4

2 回答 2

1

您正在使用 jQuery 启动 javascript 代码。ExtJS 有自己的代码启动器。您的代码需要在onReady()方法内。

例子:

Ext.onReady(function() {
    var store = new Ext.data.Store(
    .
    .
    . // rest of your code
}); 

由于您使用的是 ExtJs4,因此也请尝试新的MVC 应用程序架构

于 2011-05-05T13:04:08.250 回答
0

您的商店需要这样的模型

Ext.define('AM.model.User', {
    extend: 'Ext.data.Model',
    fields: ['id', 'name', 'email']
});

查看 extjs 4 中的 New store 定义的这个示例(来自简单的应用程序示例)并尝试使用 MVC 应用程序架构

Ext.define('AM.store.Users', {
    extend: 'Ext.data.Store',
    model: 'AM.model.User',
    autoLoad: true,

    proxy: {
        type: 'ajax',
        api: {
            read: 'data/users.json',
            update: 'data/updateUsers.json'
        },
        reader: {
            type: 'json',
            root: 'users',
            successProperty: 'success'
        }
    }
});

希望有帮助

于 2011-05-12T23:11:00.407 回答