我遵循"精通Dojo"第3章中的示例,使用dijox.grid.Grid。我稍微修改了一下,使用dojox.grid.EnhancedGrid。我已经编写了一个web服务,它以dojo所需的格式返回一些json。我已经独立测试了web服务,它返回了正确的json。但是,当我将EnhancedGrid与ItemFileReadStore放在一起时,它不会在浏览器错误控制台中产生任何错误,但也不会在网格中显示任何数据。
我可以从这里采取什么步骤来调试它?是否有一些详细的调试标志,我可以给dojo,以便它(希望)提示我出了什么问题?
编辑:我是这样做的:
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/dojo/1.6.1/dojo/dojo.xd.js" djConfig="parseOnLoad:true, isDebug:true"></script>
<link rel="stylesheet" href="/css/main.css"/>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/dojo/1.6.1/dojo/resources/dojo.css"/>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/dojo/1.6.1/dijit/themes/claro/claro.css"/>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/dojo/1.6.1/dojox/grid/enhanced/resources/claro/EnhancedGrid.css"/>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojox/grid/enhanced/resources/EnhancedGrid_rtl.css"/>
<script type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("dojox.grid.EnhancedGrid");
</script>
</head>
</body class="claro">
<style>
#msgs {
width=550px;
height=200px;
}
</style>
<div dojoType="dojo.data.ItemFileReadStore" jsId="xstore" url="/path/to/my/resource/data.json"></div>
<table id="msgs" dojoType="dojox.grid.EnhancedGrid" store="xstore">
<thead>
<tr>
<th field="id" width="50">Id</th>
<th field="ts" width="100">Date</th>
<th field="msg" width="400">Message</th>
</tr>
</thead>
</table>
</body>
</html>
返回的javascript是这样的:
{
"identifier":"id",
"items":[
{
"id":"3425",
"custId":"2342525225",
"ts":"2011-07-23T07:00:00Z",
"msg":"test message"
}
]
}
我猜一个开放的问题:json有一个额外的列,不显示在表("custId")。我希望这不会造成问题!
EDIT2:
如果我进入firebug的DOM控制台,我可以看到xstore变量正确地保存了JSON中的数据。
有两件事是:
在表上设置一个内联样式来设置宽度/高度,或者
设置EnhancedGrid属性autoHeight这就是我最终做的。