我正在尝试使用数据库将 ExtJs 连接到 PHP,并且无法向网格面板显示数据,我很困惑为什么网格面板中没有数据显示并且萤火虫中没有错误。任何人都可以检查并纠正我或教如何使用 PHP 创建一个简单的网格面板。我正在使用 Extjs 5
//应用商店/
Ext.define('TestPhp.store.Employee', {
extend: 'Ext.data.JsonStore',
alias: 'store.employees',
model: 'TestPhp.model.Employ',
proxy: {
type: 'ajax',
url: 'test.php',
reader: {
type: 'json',
rootPropety: 'data'
}
}, });
//应用程序/模型/
Ext.define('TestPhp.model.Employ', {
extend: 'Ext.data.Model',
fields: ['name','bounty','power'],
});
//应用程序/视图/主/
Ext.define('TestPhp.view.main.Grid', {
extend: 'Ext.Panel',
xtype: 'gridp',
require:['TestPhp.store.Employee'],
store: 'Employee',
items:[{
style: 'padding-top: 10px;',
xtype: 'grid',
style: 'margin-top:5px;margin-left:10px;',
columns : [
{
text : 'Name',
width : '40%',
sortable : false,
dataIndex: 'name'
},
{
text : 'Bounty',
width : '30%',
sortable : true,
dataIndex: 'bounty'
},
{
text : 'Power',
width : '30%',
sortable : true,
dataIndex: 'power'
}
],
width: '100%'
}],
});
//我的php文件
<?php
mysql_connect("localhost", "root", "") or
die("Could not connect: " . mysql_error());
mysql_select_db("test_db");
$query= "SELECT * FROM pirate";
$result= mysql_query($query);
$return_arr= array();
while($rows = mysql_fetch_array($result, MYSQL_ASSOC)){
// $row_array['id']=$rows['id'];
$row_array['name']=$rows['name'];
$row_array['bounty']=$rows['bounty'];
$row_array['power']=$rows['power'];
array_push($return_arr, $row_array);
}
$ans = array('success' => true, );
$ans['data'] = $return_arr;
header('Content-Type: application/json');
print json_encode($ans);
exit;
?>
这是php文件的输出.....
{"success":true,"data":[{"name":"luffy","bounty":"400000000","power":"gum gum no mi and haki"},{"name":"zorro ","bounty":"300000000","power":"3剑式和霸气"},{"name":"sanji","bounty":"100000000","power":"黑脚式和霸气"},{"name":"Ace","bounty":"400000000","power":"flare flare no mi and haki"},{"name":"sabo","bounty":"40000000000" ,"power":"unknown"},{"name":"rayleigh","bounty":"unknown","power":"unknown"}]}