2014-10-06 58 views
0

//在routes.jsREQ從下一()

test = require('test'); 

app.get('/test', function(req, res) { 
    test.first(
    req,res, 
    test.second, 
    'info' 
); 
}); 

//在test.js

exports.first= function(req, res, next, inf){ 
    req.test= inf; 
    console.log(inf); //info 
    next(); 
}; 
exports.second= function(req, res, next){ 
    console.log(req); //undefined 
    res.jsonp(req.test);//error :s 
}; 

這是從how to call a controller with express routes and include a defined parameter

+0

你在哪裏叫第二? – mithunsatheesh 2014-10-06 17:09:04

+0

在test.first – coiso 2014-10-06 17:09:56

+0

的下一個()中,究竟在上面的代碼中? – mithunsatheesh 2014-10-06 17:11:10

回答

4

假設一個後續問題調用時未定義您在test.first()中調用next();,這意味着您沒有將參數傳遞給test.second()。因此,使用您當前的設置,您需要在test.first()中執行next(req, res);

+0

thaaaaanks !!!!! – coiso 2014-10-06 17:31:45