1

我正在尝试使用 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);

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

谢谢!

我在 JSONLint 测试了 JSON 的有效性,它说它是有效的。

4

1 回答 1

2

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).

于 2011-01-07T17:33:45.077 回答