大家好, 我有 ExtJS 3.2 、 PHP5.3 和 Oracle 10g XE。
从 MyExtJs.php 返回 JSON:
[{"FIRST_NAME":"艾伦","LAST_NAME":"阿贝尔"},{"FIRST_NAME":"桑达尔","LAST_NAME":"安德"}, {"FIRST_NAME":"莫哲","LAST_NAME":"阿特金森"},{"FIRST_NAME":"大卫","LAST_NAME":"奥斯汀"},{"FIRST_NAME":"赫尔曼","LAST_NAME":"贝尔"},{"FIRST_NAME":"雪莉","LAST_NAME":"拜达"},{"FIRST_NAME":"阿米特","LAST_NAME":"类达"},{"FIRST_NAME":"伊丽莎白","LAST_NAME":"贝茨"},{"FIRST_NAME":"莎拉","LAST_NAME":"贝尔"},{"FIRST_NAME":"大卫","LAST_NAME":"伯恩斯坦"}]
数据存储:
var store = new Ext.data.JsonStore( {
autoLoad: true,
url: 'MyExtJs.php',
fields: [
{name: 'firstname'},
{name: 'lastname'}
]
});
网格:
var grid = new Ext.grid.GridPanel({
store: store,
columns: [
{
id : 'fname',
header : 'First Name',
width : 160,
sortable : true,
dataIndex: 'firstname'
},
{
id : 'lname',
header : 'Last Name' ,
width : 75,
sortable : true,
dataIndex: 'lastname'
}
],
stripeRows: true,
height: 300,
width: 500,
title: 'Report',
autoExpandColumn: 'lname',
stateful: true,
stateId: 'grid'
});
我只显示网格的标题和边框,但内部没有数据。
亲切的问候, 丹
最佳答案
在您的字段配置中包含一个“映射”属性,如下所示:
var store = new Ext.data.JsonStore( {
autoLoad: true,
url: 'MyExtJs.php',
fields: [
{name: 'firstname', mapping:'FIRST_NAME'},
{name: 'lastname', mapping:'LAST_NAME'}
]
});
读取 JSON 的不是 Ext.data.Store,它内部使用 Ext.data.DataReader 来读取来自服务器的数据,Store 配置中设置的“fields”属性会传递给其 DataReader 来配置自身。 DataReader 使用 Ext.data.Field 来读取每个字段,查看 here ,ExtJS的文档很好!
关于php - ExtJs Grid 中的 JsonStore 数据未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5030980/