2
votes

Here is the Src code for HTML file

<!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>

File path: /bh/Main.js [Main File]

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'
        }
       ]
  });
 }
});

File path: /app/controller/UserController.js [Controller]

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

File path: /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'
  }
});

File path: /app/model/UserModel.js [Model]

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'}
]
});

File path: /app/view/UserList.js [View]

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);
}

});

In fire bug it shows the JSON response as follows:

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

Why the Data has not been displayed although I have a valid json response. Please help!!!

enter image description here

2
Oh wat is this I have written extends instead of extend in the Store file it should be extend:'Ext.data.Model' - aswininayak
You have valid JSON response, but do you have records in the store? - sha
can you please share the solution if you have? - Patton
@Patton Check my answer, he just need to configure the reade, since he is using the generic Ext.data.Store. - VoidMain

2 Answers

0
votes

I believe your grid did not load because you did not load the store properly. You should use.

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

instead of

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

You should configure your reader in the proxy, like this:

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