YUI 数据表不采用 JSON

发布于 2024-10-10 21:07:03 字数 1115 浏览 2 评论 0原文

我正在尝试使用 YUI 用 JSON 填充数据表,

我有这个 JSON:

[{"test":"value1",
"test2":"value2",
"test3":"value3",
"topic_id":"123139007E57",
"gmt_timestamp":1553994442,
"timestamp_diff":-1292784933382,
"status":"images\/statusUp.png",
"device_id":"568FDE9CC7275FA"}, ..

它在大约 20 个不同的设备上继续这样,我用 ] 关闭它

我只想打印数据表中的选择键,以便我的列定义看起来像这样:

var myColumnDefs = [
    {key:"test", sortable:true, resizeable:true},
    {key:"test2", sortable:true, resizeable:true},
    {key:"topic_id", sortable:true, resizeable:true},
    {key:"status", sortable:true, resizeable:true},
    {key:"device_id", sortable:true, resizeable:true},
];

var myDataSource = new YAHOO.util.DataSource(bookorders);
        myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
        myDataSource.responseSchema = {
            fields: ["test","test2","topic_id","status","device_id"]
        };


    var myDataTable = new YAHOO.widget.DataTable("basic",
            myColumnDefs, myDataSource);

由于某种原因打印数据错误,我做错了什么?

谢谢!

我已经在 J​​SONLint 上测试了 JSON 的有效性,它说它是有效的。

I am trying to fill a Datatable with a JSON using YUI,

I have this JSON:

[{"test":"value1",
"test2":"value2",
"test3":"value3",
"topic_id":"123139007E57",
"gmt_timestamp":1553994442,
"timestamp_diff":-1292784933382,
"status":"images\/statusUp.png",
"device_id":"568FDE9CC7275FA"}, ..

It continues like this with about 20 different devices, and I close it with a ]

I just want to print select keys in the datatable so my Column Definitions look like this:

var myColumnDefs = [
    {key:"test", sortable:true, resizeable:true},
    {key:"test2", sortable:true, resizeable:true},
    {key:"topic_id", sortable:true, resizeable:true},
    {key:"status", sortable:true, resizeable:true},
    {key:"device_id", sortable:true, resizeable:true},
];

var myDataSource = new YAHOO.util.DataSource(bookorders);
        myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
        myDataSource.responseSchema = {
            fields: ["test","test2","topic_id","status","device_id"]
        };


    var myDataTable = new YAHOO.widget.DataTable("basic",
            myColumnDefs, myDataSource);

It's print Data Error for some reason, what am I doing wrong?

Thanks!

I have tested the validity of the JSON at JSONLint and it says it is valid.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

情泪▽动烟 2024-10-17 21:07:11

如果您使用 JSON,我认为您的数据源响应类型应该是该类型:YAHOO.util.DataSource.TYPE_JSON 而不是 TYPE_JSARRAY。您是否看过以下示例: developer.yahoo.com/yui/examples/datatable /dt_xhrjson.html

你能用Firebug看看到底是哪个错误吗?查看响应是否正常以及返回哪个 json。如果您认为这是 json 的问题,您可以使用像 Jackson 这样的库在服务器中生成它(它将确保返回的 json 没问题)。

If you're using JSON, I think your datasource response type should be of that type: YAHOO.util.DataSource.TYPE_JSON instead of TYPE_JSARRAY. Have you looked at the example in: developer.yahoo.com/yui/examples/datatable/dt_xhrjson.html

Can you use Firebug to see exactly which is the error? See if the response is OK and which json is returned. If you think its a problem of the json you can use a library like Jackson to generate it in the server (it will make sure that the json returned is ok).

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