我正在尝试根据 php 文件返回的计数在面板内创建添加面板。但是,我对如何使用返回的 JSON 数据感到困惑。此外,当我使用 firebug 进行检查时,我没有看到 Ajax 调用启动。我的代码如下:
应用程序.js
var ds = Ext.create('Ext.data.Store',({
proxy: {
type:'ajax',
url:'data.php',
reader: {
type : 'json',
id: 'Completion_ID',
root: "myInventory",
fields:
[{name: 'PMNumber', type: 'int', mapping: 'PMNumber'},
]
}
}
})
);
Ext.onReady(function()
{
ds.load();
Ext.create('Ext.panel.Panel', {
renderTo: document.getElementById('aa'),
title: 'Marks Entry',
height: 500,
width: 880,
bodyStyle:'padding:15px 15px 15px 15px',
layout: {
type: 'table',
//3 by 3 Grid
columns: parseInt([{ dataIndex: 'PMNumber'}])
},
items: [{
// Blank Panels so html is ''
xtype:'panel',
html: '2003010001 '
},{
xtype:'panel',
html: '2003010002 '
},{
xtype:'panel',
html: '2003010003 '
},{
xtype:'panel',
html: '2003010004'
},
{
xtype:'panel',
html: '2003010005'
},
{
xtype:'panel',
html: '2003010006'
},
{
xtype:'panel',
html: '2003010007'
},
{
xtype:'panel',
html: '2003010008'
},
{
xtype:'panel',
html: '2003010009'
},
],
});
});
数据.php
<?php
//connection String
$con = mysql_connect($myhost, $myuser, $mypass) or die('Could not connect: ' . mysql_error());
//Select The database
$bool = mysql_select_db($myDB, $con);
if ($bool === False){
print "can't find $database";
}
// Gather all pending requests
$query = "SELECT
count(*) AS PMNumber
FROM marks " ;
$result = mysql_query($query, $con);
if (mysql_num_rows($result) > 0){
while($obj = mysql_fetch_object($result))
{
$arr[] = $obj;
}
// Now create the json array to be sent to our datastore
$myData = array('myInventory' => $arr);
echo json_encode($myData);
return;
exit();
}
else { // If no requests found, we return nothing
$myData = array('myInventory' => '');
echo json_encode($myData);
return;
exit();
}
?>
独立调用时php文件返回的JSON数据:
{"myInventory":[{"PMNumber":"3"}]}
.html 文件:
<html>
<head>
<title>Hello Ext</title>
<link rel="stylesheet" type="text/css" href="../extjs/resources/css/ext-all.css">
<script type="text/javascript" src="../extjs/ext-debug.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</head>
<body style="padding: 50px 20px 0 20px;">
<div id="aa" style="wdith:900px;height:500px"></div>
</body>
</html>
有人知道我在哪里失踪吗?
谢谢