我想更新2d數組,但它不在這裏工作。請檢查以下代碼如何更新jQuery中的2d數組?
var ksatodayvalue = [];
function pad2(n) { return n < 10 ? '0' + n : n }
var dt = new Date();
currentyear = dt.getFullYear().toString();
currentmonth = pad2(dt.getMonth() + 1);
currentday = pad2(dt.getDate());
$.getJSON(jsonrequesturl, function (data) {
$.each(data, function (index, d) {
ksatodayvalue.push("[Date.UTC("+currentyear+", "+currentmonth+", "+currentday-1+", "+d.time.split(':')[0]+", "+d.time.split(':')[1]+", "+d.time.split(':')[2]+"),3]");
});
我想要這樣的數組。
var ksatodayvalue = [[Date.UTC(2014, 03, 18, 23, 45, 00),3],[Date.UTC(2014, 03, 18, 23, 30, 00),4],[Date.UTC(2014, 03, 18, 23, 15, 00),6],[Date.UTC(2014, 03, 18, 23, 00, 00),8]];
相關? http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call – elclanrs
此外,你推一個字符串不是一個數組...什麼樣的對象是一個'Date.UTC(...)'。你的代碼沒有多大意義。我認爲你在這裏混淆了一些東西...... – elclanrs
像elclanrs說的,你只是將一個字符串推入'ksatodayvalue'。您需要推送包含適當對象/數字的數組。另外,你是否有'currentyear','currentmonth'和'currentday'定義某處? – danasilver