投放本站广告请联系:
extjscn#126.com
有个小问题,请高手指点一下
我用aaa.php
<?php echo '<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />'; $link = mssql_pconnect("192.168.0.18", "sa", "123") or die("Could not connect"); mssql_select_db("ng0001") or die("Could not select database"); $sql = "SELECT appeId,survId,location,surveyDate,surveyTime,inputUserId FROM aaa "; $rs = mssql_query($sql); while($obj = mssql_fetch_object($rs)) { $arr[] = $obj; } $json_string = json_encode($arr); echo $json_string ?>
得到数据
[{"appeId":"a ","survId":"aa ","location":"aaa ","surveyDate":"aaaa ","surveyTime":"aaaaa ","inputUserId":"aaaaaa "},
{"appeId":"b ","survId":"bb ","location":"bbb ","surveyDate":"bbbb ","surveyTime":"bbbbb ","inputUserId":"bbbbbb "}]
然后在aaa.js 中调用!!!
Ext.onReady(function(){ var proxy=new Ext.data.HttpProxy( {url:'aaa.php'}); //定义reader var reader=new Ext.data.JsonReader( { },[ {name: 'appeId', mapping: 'appeId'}, {name: 'survId' }, //如果name与mapping同名,可以省略mapping {name: 'location'}, {name: 'surveyDate'}, {name: 'surveyTime'}, {name: 'inputUserId'} ] ) //构建Store var store=new Ext.data.Store( { proxy:proxy, reader:reader }); //载入 store.load(); // create the grid var grid = new Ext.grid.GridPanel({ store: store, columns: [ {header: "appeId", width: 60, dataIndex: 'appeId', sortable: true}, {header: "survId", width: 60, dataIndex: 'survId', sortable: true}, {header: "location", width: 60, dataIndex: 'location', sortable: true}, {header: "surveyDate", width: 100, dataIndex: 'surveyDate', sortable: true}, {header: "surveyTime", width: 100, dataIndex: 'surveyTime', sortable: true}, {header: "inputUserId", width:80, dataIndex: 'inputUserId', sortable: true} ], renderTo:'example-grid', width:540, height:200 }); });
最后的aaa.html内容
<head> <meta http-equiv="Content-Type" content="text/html; charset=GB2312" /> <title>ExtJS</title> <link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css" /> <script type="text/javascript" src="extjs/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="extjs/ext-all.js"></script> <script type="text/javascript" src="aaa.js"></script> </head> <body> <div id="example-grid"></div> </body> </html>
但是得不出数据
附件 | 大小 |
---|---|
aaa.JPG | 89.77 千字节 |
- 要发表评论,请先登录
程序写得没有问题
我将你的代码复制到我本机上,可以运行成功。
注意以下几点:
1、以上例子在ExtJs 2.02下是可以成功的。
2、如果第一条没有问题,
请检查你PHP返回的数据是否跟你贴出来的一样(在firebug中可以看到!)。