我在jQuery中使用.data()函數將從服務器返回的一組記錄附加到我的頁面上的DOM元素。記錄以對象數組的形式存儲。代碼如下:加載客戶端對象數組的jQuery數據表
//Attached returned data to an HTML table element
$('#measTable').data('resultSet', resultSet);
//Get stored data from HTML table element
var results = $('#measTable').data('resultSet');
//Construct the measurement table
data_table = $('#measTable').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bProcessing": true,
"bDeferRender": true,
"aaData": [ results ],
"aoColumns": [
{ "mDataProp": "Field1" },
{ "mDataProp": "Field2" },
{ "mDataProp": "Field3" },
{ "mDataProp": "Field4" }
]
});
然後我從元素中獲取數據並繼續將其加載到數據表中。但是這似乎不起作用,並始終返回錯誤請求來自數據源的第0行的未知參數「Field1」。是否有可能以這種方式將數據加載到數據表中?
UPDATE:
下面是結果對象陣列的樣品
results =
0: Object
Field1: "2011/04/23"
Field2: 8
Field3: "Hello"
Field4: "World"
__proto__: Object
1: Object
Field1: "2011/03/25"
Field2: 6
Field3: "Hello"
Field4: "Everyone"
__proto__: Object
...etc.
你能發表'結果'的內容嗎? –
嗨,亞當,剛剛發佈了結果對象數組的代碼片段。 – kingrichard2005
DataTables博客上有一個[post](http://www.datatables.net/blog/Extended_data_source_options_with_DataTables)。你使用1.8嗎?這絕對不能在早期版本中使用。 – Seth