yui 数据表错误
我在 DataTable 中插入 json 数据时遇到问题。 这是服务器发送的 json 数据的示例:
{"geneItemList":"{"col":"symbol","qv":"cd4","limit":"-1","start":"0","geneid":"920","name":"CD4"
,"symbol":"CD4","lastupdated":"2009-05-20 10:01:52.0","lastmodified":"2009-05-20 11:12:37.0"}
,...
这里是我的 YUI 代码:
<script type="text/javascript">
YAHOO.namespace("local");
var qct = YAHOO.local;
YAHOO.util.Event.addListener(window, "load", function() {
qct.RowSelection = function() {
var myColumnDefs = [
{key:"geneid", label:"Gene", formatter: "number", sortable:true},
{key:"name", label:"Name", sortable:true},
{key:"symbol", label:"Symbol", sortable:true},
{key:"lastupdated", label:"Last Updated", formatter:"date", sortable:true},
{key:"lastmodified", label:"Last Modified", formatter:"date", sortable:true}
];
var myDataSource = new YAHOO.util.DataSource("qct-list.html");
myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
myDataSource.connXhrMode = "queueRequests";
myDataSource.responseSchema = {
resultsList: "geneItemList",
fields: [{key:"col", parser:"string"},
{key:"qv", parser:"string"},
{key:"limit", parser:"number"},
{key:"start", parser:"number"},
{key:"geneid", parser:"number"},
{key:"name", parser:"string"},
{key:"symbol", parser:"string"},
{key:"lastupdated", parser:"date"},
{key:"lastmodified", parser:"date"}]
};
// test this
var myGeneListTable = new YAHOO.widget.DataTable("geneListTable", myColumnDefs, myDataSource,
{initialRequest:"?col=<c:out value="${fieldName}"/>&qv=<c:out value="${queryValue}"/>&start=<c:out value="${start}"/>&limit=<c:out value="${limit}"/>", selectionMode:"single"});
etc...
当我测试我的页面时,出现“数据错误”。 在我的数据表中!
知道出了什么问题吗?
I have a problem with json data insertion in my DataTable.
Here an example of json data send by server:
{"geneItemList":"{"col":"symbol","qv":"cd4","limit":"-1","start":"0","geneid":"920","name":"CD4"
,"symbol":"CD4","lastupdated":"2009-05-20 10:01:52.0","lastmodified":"2009-05-20 11:12:37.0"}
,...
And here my YUI code:
<script type="text/javascript">
YAHOO.namespace("local");
var qct = YAHOO.local;
YAHOO.util.Event.addListener(window, "load", function() {
qct.RowSelection = function() {
var myColumnDefs = [
{key:"geneid", label:"Gene", formatter: "number", sortable:true},
{key:"name", label:"Name", sortable:true},
{key:"symbol", label:"Symbol", sortable:true},
{key:"lastupdated", label:"Last Updated", formatter:"date", sortable:true},
{key:"lastmodified", label:"Last Modified", formatter:"date", sortable:true}
];
var myDataSource = new YAHOO.util.DataSource("qct-list.html");
myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
myDataSource.connXhrMode = "queueRequests";
myDataSource.responseSchema = {
resultsList: "geneItemList",
fields: [{key:"col", parser:"string"},
{key:"qv", parser:"string"},
{key:"limit", parser:"number"},
{key:"start", parser:"number"},
{key:"geneid", parser:"number"},
{key:"name", parser:"string"},
{key:"symbol", parser:"string"},
{key:"lastupdated", parser:"date"},
{key:"lastmodified", parser:"date"}]
};
// test this
var myGeneListTable = new YAHOO.widget.DataTable("geneListTable", myColumnDefs, myDataSource,
{initialRequest:"?col=<c:out value="${fieldName}"/>&qv=<c:out value="${queryValue}"/>&start=<c:out value="${start}"/>&limit=<c:out value="${limit}"/>", selectionMode:"single"});
etc...
When I test my page, I have "Data error." in my datatable!
An idea what is wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了解决问题的方法。
json 出错了!
差:
好:
这只是一个语法问题!
如果 YUI DataTable 出现“数据错误”,首先要做的就是查看服务器的 JSON 响应。
I found the solution to my problem.
It was a mistake to json!
Bad :
Good :
It was just a syntax problem!
If you have a "data error" with YUI DataTable, the first thing to do is look at the JSON response from the server.
有些工具可以帮助调试您的 JSON!
您可以使用: http://www.jsonlint.com/ (跟踪您的错误)
语法帮助: http://en.wikipedia.org/wiki/JSON
另一个技巧是使用 yui debug模式,测试新脚本时。
例如:.../json-debug.js
Some tools can help to debug your JSON !
You can use : http://www.jsonlint.com/ (to track your errors)
Syntax help : http://en.wikipedia.org/wiki/JSON
Another tips, is using yui debug mode, when testing new script.
Ex : .../json-debug.js