2012-03-29 30 views
2

這裏呈現的是HTML文件的Src代碼GRID沒有正確的ExtJS 4使用存儲

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4 /strict.dtd"> 
<html> 
<head> 
<title>MVC Architecture</title> 
<link rel="stylesheet" type="text/css" href="/bh/extjs/resources/css/ext-all.css" /> 
<script type="text/javascript" src="extjs/ext-debug.js"></script> 
<script type="text/javascript" src="Main.js"></script> 
</head> 
<body> 
</body> 
</html> 

文件路徑:/bh/Main.js [主文件]

Ext.require('Ext.container.Viewport'); 
Ext.application({ 
name: 'App', 
appFolder: 'app', 
controllers: ['UserController'], 

launch: function() { 

Ext.create('Ext.container.Viewport', { 
layout: 'border', 
items: [ 
     { 
      xtype: 'userList' 
     } 
     ] 
    }); 
} 
}); 

文件路徑:/app/controller/UserController.js [控制器]

Ext.define('App.controller.UserController',{ 
extend: 'Ext.app.Controller', 
stores: ['UserStore'], 
models:['UserModel'], 
views:['user.UserList'], 
init: function() { 
    this.getUserStoreStore().load(); 
    } 
}); 

文件路徑:/app/store/UserStore.js

Ext.define('App.store.UserStore', { 
    extend: 'Ext.data.Store', 
    model: 'App.model.UserModel', 

    proxy: { 
    type: 'ajax', 
    url: 'app/data/contact.json' 
    } 
}); 

文件路徑:/app/model/UserModel.js [模型]

Ext.define('App.model.UserModel',{ 
extends:'Ext.data.Model', 
fields:[ 
    {name: 'name', type: 'string'}, 
    {name: 'age', type: 'string'}, 
    {name: 'phone', type: 'string'}, 
    {name: 'email', type: 'string'} 
] 
}); 

文件路徑:/app/view/UserList.js [查看]

Ext.define('App.view.user.UserList' ,{ 
extend: 'Ext.grid.Panel', 
alias:'widget.userList', 
title:'Contacts', 
region:'center', 
resizable:true, 
initComponent: function() { 
this.store = 'UserStore'; 
this.columns = [ 
      {text: 'Name',flex:1,sortable: true,dataIndex: 'name'}, 
      {text: 'Age',flex:1,sortable: true,dataIndex: 'age'}, 
      {text: 'Phone',flex:1,sortable: true,dataIndex: 'phone'}, 
      {text: 'Email',flex:1,sortable: true,dataIndex: 'email'} 
     ]; 

this.callParent(arguments); 
} 

}) ;

在發生火災的錯誤它顯示了JSON迴應如下:

[{ 
    "name": "Aswini", 
    "age": "32", 
    "phone": "555-555-5555", 
    "email": "[email protected]" 
}] 

爲什麼數據還未顯示出來,儘管我有一個有效的JSON響應。請幫忙!!!

enter image description here

+0

哦笏這是我寫延伸,而不是在存儲擴展文件,它應擴展:'Ext.data.Model' – aswininayak 2012-03-29 13:21:05

+0

您有有效的JSON響應,但是您有商店中的記錄嗎? – sha 2012-03-30 15:53:31

+0

如果有,請分享解決方案嗎? – Patton 2012-04-05 09:17:07

回答

0

我相信你的網格沒有加載,因爲你沒有正確裝載存儲。你應該使用。的

this.getStore('userStore').load(); 

代替

this.getUserStoreStore().load(); 
+0

當您在定義商店的Controller中使用它們時,這兩個調用是等同的。 – VoidMain 2012-10-06 19:24:44

0

您應該配置你的讀者在代理,像這樣:

Ext.define('App.store.UserStore', { 
    extend: 'Ext.data.Store', 
    model: 'App.model.UserModel', 
    proxy: { 
     type: 'ajax', 
     url: 'app/data/contact.json', 
     reader: { 
      type: 'json' 
     } 
    } 
});