5

次のようにdataTableにデータを入力しようとしています:

$("#my-datatable").dataTable( {
    "sAjaxSource" : "/someURLOnMyServer",
    "bDestroy" : true,
    "fnServerParams" : function(serverParams) {
        serverParams.push(
            {
                "name" : "widget",
                "value" : token
            }
        );
    }
});

そして、それが入力している HTML テーブル:

<table id="my-datatable">
    <thead>
        <tr>
            <th>Type</th>
            <th>Value</th>
            <th>ID</th>
            <th>Fizz</th>
            <th>Buzz</th>
        </tr>
    </thead>
    <tbody></tbody>
</table>

Firebug によると、サーバーから返される JSON は次のとおりです。

[
   {
      "id":1,
      "attributeType":{
         "id":1,
         "name":"test1",
         "tag":"test-type",
         "is-dog":false
      },
      "attributeValue":{
         "id":null,
         "name":"blah",
         "tag":"BLAH"
      },
      "buzz":1,
      "fizz":"53abc"
   }
]

しかし、Firebug はコンソールに次の JavaScript エラーをスローしています。

TypeError: aData is undefined
[Break On This Error]   

for ( i=0 ; i<aData.length ; i++ ) --> jquery.dataTables.js (line 2541)

誰が何が問題なのかを見つけることができますか? オブジェクトを正しく設定していないdataTableか、返された JSON が入力しようとしている HTML テーブルの「スキーマ」と一致しません。いずれにせよ、私は迷っています。前もって感謝します!

4

2 に答える 2

1

JSON オブジェクトをaaData次のように囲みます。

{"aaData" : 

[{"id":1,"attributeType":{"id":1,"name":"test1","tag":"test-type","is-dog":false},"attributeValue":{"id":null,"name":"blah","tag":"BLAH"},"buzz":1,"fizz":"53abc"}]

}
于 2012-10-11T20:12:06.183 に答える