문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top