yui 数据表错误

发布于 2024-07-22 18:04:35 字数 2328 浏览 10 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白色秋天 2024-07-29 18:04:35

我找到了解决问题的方法。
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 响应。

I found the solution to my problem.
It was a mistake to json!

Bad :

{"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"}
,...

Good :

{"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"}
,...}**]**
}

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.

蓝眼泪 2024-07-29 18:04:35

有些工具可以帮助调试您的 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文