2015-10-20 102 views
0

如何使用busboy獲取數組表單數據?從Busboy獲取表單數組數據

在路線:

req.busboy.on('field', function(fieldname, val){ 
    //fieldname is string, expecting array 
    //'bunnies[gray]', etc... 
}); 

而我的觀點:

form(method="post" action="/post/path" enctype="multipart/form-data") 
    input(name="bunnies[gray]") 
    input(name="bunnies[white]") 
    input(name="bunnies[black]") 
    input(name="bunnies[brown]") 
    input(name="bunnies[purple]") 

回答

0

的問題是很舊,但在這個問題的情況下別人絆倒,這裏就是我所做的:

var arr = new Array(); 

req.pipe(req.busboy); 

req.busboy.on('field', function(key, value) { 
    if(key === 'array_name[]') { 
    arr.push(value); 
    } 
}); 

req.busboy.on('finish', function() { 
    console.log(arr); 
});