yui数据表错误

时间:2009-05-29 21:24:47

标签: ajax json yui yui-datatable

我的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...

当我测试我的页面时,我有“数据错误”。在我的数据表中!

一个想法是什么问题?

2 个答案:

答案 0 :(得分:2)

我找到了解决问题的方法。 这是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"}
,...

好:

{"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 DataTable有“数据错误”,首先要做的是查看服务器的JSON响应。

答案 1 :(得分:0)

某些工具可以帮助您调试JSON!

您可以使用:http://www.jsonlint.com/(跟踪您的错误)

语法help:http://en.wikipedia.org/wiki/JSON

另一个提示是,在测试新脚本时使用yui调试模式。

Ex:... / json-debug.js