2011-05-05 150 views
0

我想加載一個JSON字符串到EXTJS網格。我得到的錯誤是來自ext-all-debug.js的Uncaught TypeError: Cannot read property 'prototype' of undefined問題與EXTJS 4網格

這是我的代碼爲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" [email protected]("~/Content/resources/css/ext-all.css") /> 
    <link rel="stylesheet" type="text/css" [email protected]("~/Content/examples/shared/example.css") /> 
    <script type="text/javascript" [email protected]("~/Content/bootstrap.js")></script> 


     <script type="text/javascript" [email protected]("~/Content/examples/grid/FIO8472-JSON.js")></script> 
    } 
<div id="example-grid"></div> 
<div id="example-grid2"></div> 

任何幫助表示讚賞。

+0

在這裏看到:http://whatisextjs.com/extjs-4-ajax/asp-net-ajax-extjs-4-grid-4 – 2011-12-16 14:52:48

回答

0

你的店需要的模型
這樣的:

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

看起來本例新店定義的ExtJS 4「(從簡單的應用程序爲例) ,並嘗試使用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' 
     } 
    } 
}); 

希望幫助

1

您正在使用jQuery啓動JavaScript代碼。 ExtJS有它自己的代碼啓動器。您的代碼需要在onReady()方法中。

例子:

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

由於您使用ExtJs4,嘗試新的MVC application architecture爲好。

+0

仍然有相同的錯誤。還有其他建議嗎? – Patrick 2011-05-05 13:26:06

+0

您是否嘗試顯示簡單的消息框而不是完整的代碼?嘗試一些簡單的..只是爲了測試.. – 2011-05-05 15:30:34

+0

工程,消息框,Ext.Msg.alert('狀態','更改成功保存'); – Patrick 2011-05-05 16:54:14