如何使用 datatables处理parse.com javascript数据?
我无法显示从parse.com检索到的数据,是否有任何建议?
我不确定这是否正确:
$(document).ready(function () {
var results = [];
Parse.initialize("Application ID", "Javascript Key");
var Score = Parse.Object.extend("Score");
var query = new Parse.Query(Score);
query.ascending("Date");
query.find({
success: function (results) {
for (var i = 0; i < results.length; i++) {
var object = results[i];
var Username = object.get('Username');
var Game = object.get('Game');
var Accuracy = object.get('Accuracy');
var TimeUsed = object.get('TimeUsed');
var Date = object.get('Date');
var Time = object.get('Time');
console.log(JSON.stringify(results));
results.push({
Username: Username,
Game: Game,
Accuracy: Accuracy,
TimeUsed: TimeUsed,
Date: Date,
Time: Time
});
}
}
});
$('#example').DataTable({
data: results
});
});
答案 0 :(得分:0)
我看到的问题是你试图通过传入一个JSON文件来调用DataTable
。我认为你的方法只适用于普通数组。另一方面,您的数组包含JSON。这样的事情应该有效:
$('#example').dataTable({
"bProcessing": true,
"aaData": data,// <-- your array of objects
"aoColumns": [
{ "mData": "Username" }, // <-- which values to use inside object
{ "mData": "Game" },
{ "mData": "Accuracy" },
{ "mData": "TimeUsed" },
{ "mData": "Date" }
]
});
您可以使用aaData
传递对象数组,然后指定哪个列将接收哪些数据。