如何构造这个数组

时间:2015-05-22 11:24:42

标签: javascript arrays

我正在尝试转换此格式的数据:

  data.addRows([
    [new Date(2011, 1, 23), , '<div>Conversation</div><img src="img/comments-icon.png" style="width:32px; height:32px;">', '', ''],
    [new Date(2011, 1, 23, 23, 0, 0), , '<div>Mail from boss</div><img src="img/mail-icon.png" style="width:32px; height:32px;">', '', ''],
    [new Date(2011, 1, 24, 16, 0, 0), , 'Report', '', ''],
    [new Date(2011, 1, 26), new Date(2011, 2, 2), 'Traject A', '', ''],
    [new Date(2011, 1, 27), , '<div>Memo</div><img src="img/notes-edit-icon.png" style="width:48px; height:48px;">', '', ''],
    [new Date(2011, 1, 29), , '<div>Phone call</div><img src="img/Hardware-Mobile-Phone-icon.png" style="width:32px; height:32px;">', '', ''],
    [new Date(2011, 1, 28), new Date(2011, 2, 3), 'Traject B', '', ''],
    [new Date(2011, 2, 4, 4, 0, 0), , '<div>Report</div><img src="img/attachment-icon.png" style="width:32px; height:32px;">', 'http://images.clipartpanda.com/test-clip-art-cpa-school-test.png', 'test2']
  ]);

为:

 data.addRows(dataNew);

在javascript中创建此数组的最佳方法是什么:

[
    [new Date(2011, 1, 23), , '<div>Conversation</div><img src="img/comments-icon.png" style="width:32px; height:32px;">', '', ''],
    [new Date(2011, 1, 23, 23, 0, 0), , '<div>Mail from boss</div><img src="img/mail-icon.png" style="width:32px; height:32px;">', '', ''],
    [new Date(2011, 1, 24, 16, 0, 0), , 'Report', '', ''],
    [new Date(2011, 1, 26), new Date(2011, 2, 2), 'Traject A', '', ''],
    [new Date(2011, 1, 27), , '<div>Memo</div><img src="img/notes-edit-icon.png" style="width:48px; height:48px;">', '', ''],
    [new Date(2011, 1, 29), , '<div>Phone call</div><img src="img/Hardware-Mobile-Phone-icon.png" style="width:32px; height:32px;">', '', ''],
    [new Date(2011, 1, 28), new Date(2011, 2, 3), 'Traject B', '', ''],
    [new Date(2011, 2, 4, 4, 0, 0), , '<div>Report</div><img src="img/attachment-icon.png" style="width:32px; height:32px;">', 'http://images.clipartpanda.com/test-clip-art-cpa-school-test.png', 'test2']
]

2 个答案:

答案 0 :(得分:0)

只需将数组分配给变量:

var dataNew = [
   [new Date(2011, 1, 23), , '<div>Conversation</div><img src="img/comments-icon.png" style="width:32px; height:32px;">', '', ''],
   [new Date(2011, 1, 23, 23, 0, 0), , '<div>Mail from boss</div><img src="img/mail-icon.png" style="width:32px; height:32px;">', '', ''],
   [new Date(2011, 1, 24, 16, 0, 0), , 'Report', '', ''],
   [new Date(2011, 1, 26), new Date(2011, 2, 2), 'Traject A', '', ''],
   [new Date(2011, 1, 27), , '<div>Memo</div><img src="img/notes-edit-icon.png" style="width:48px; height:48px;">', '', ''],
   [new Date(2011, 1, 29), , '<div>Phone call</div><img src="img/Hardware-Mobile-Phone-icon.png" style="width:32px; height:32px;">', '', ''],
   [new Date(2011, 1, 28), new Date(2011, 2, 3), 'Traject B', '', ''],
   [new Date(2011, 2, 4, 4, 0, 0), , '<div>Report</div><img src="img/attachment-icon.png" style="width:32px; height:32px;">', 'http://images.clipartpanda.com/test-clip-art-cpa-school-test.png', 'test2']
];

data.addRows(dataNew);

答案 1 :(得分:0)

我建议看一下阵列基础:)

$stmt = $db->prepare("INSERT INTO users (Fuid, Ffname, Femail) 
  VALUES (?, ?, ?) 
ON DUPLICATE KEY UPDATE users 
  SET Ffname = ?, Femail = ?");
$stmt->bind_param('issss',$fuid_db,$ffname_db, $femail_db,$ffname_db, $femail_db)
$stmt->execute();