2015-11-29 57 views
0

我想從路由數組中傳遞數組來查看頁面。我說我想傳遞的數據是:傳遞數組從路由查看node.js

[ 
    [10, 10], 
    [20, 50], 
    [30, 120], 
    [40, 80], 
    [50, 90], 
    [60, 50], 
    [70, 70], 
    [80, 90], 
    [90, 150], 
    [100, 50], 
    [110, 40], 
    [120, 70], 
    [130, 20], 
    [140, 40], 
    [200, 30] 
] 

我得到它在以下格式:

["10,10,20,50,30,120,40,80,50,90,60,50,70,70,80,90,90,150,100,50,110,40,120,70,130,20,140,40,200,30"] 

,但我需要它,我發送相同的格式。 我index.js(路線文件)是:

router.get('/', function(req, res, next) { 
var dataset = [ 
    [10, 10], 
    [20, 50], 
    [30, 120], 
    [40, 80], 
    [50, 90], 
    [60, 50], 
    [70, 70], 
    [80, 90], 
    [90, 150], 
    [100, 50], 
    [110, 40], 
    [120, 70], 
    [130, 20], 
    [140, 40], 
    [200, 30] 
]; 
console.log(dataset); 
res.render('index',{"data" : [dataset]}); 
}); 

module.exports = router; 

,並在我的視圖文件,我試圖把它想:

<div class="hold_data" data-info={{data}}></div> 

,如果有人知道如何可以做到這一點請建議。感謝提前:)

+0

嘗試將其作爲值添加到鍵中。這應該工作。另外,有些代碼會更好地幫助您進行調試。分享你的代碼。 – Bazinga777

+0

@ Bazinga777:在問題中增加了更多信息。請看now –

+0

'res.render('index',{「data」:dataset});'用這個..看看這是否有幫助.. – Chandan

回答

1

如下嘗試JSON.stringify -

res.render('index',{"data" : JSON.stringify(dataset)}); 

希望這有助於。