2013-10-02 68 views
1

我開發與node.js的一個簡單的應用程序,並表示,幾乎所有的是好的,但我得到這個錯誤:類型錯誤:對象#<IncomingMessage>有沒有方法「渲染」

res.render("aggregatedCostList",{ 
    ^
TypeError: Object #<IncomingMessage> has no method 'render' 
at /home/arpho/Projects/myBalance/routes/index.js:90:11 
at /home/arpho/Projects/myBalance/node_modules/async/lib/async.js:116:25 
at /home/arpho/Projects/myBalance/node_modules/async/lib/async.js:24:16 
at /home/arpho/Projects/myBalance/routes/index.js:87:7 
at /home/arpho/Projects/myBalance/node_modules/orientdb/lib/orientdb/db.js:539:24 
at toRidsFromORIDsOfDocument (/home/arpho/Projects/myBalance/node_modules/orientdb/lib/orientdb/db.js:507:16) 
at toRidsFromORIDsOfDocuments (/home/arpho/Projects/myBalance/node_modules/orientdb/lib/orientdb/db.js:534:9) 
at Object.callback (/home/arpho/Projects/myBalance/node_modules/orientdb/lib/orientdb/db.js:302:9) 
at EventEmitter.Manager.readResponse (/home/arpho/Projects/myBalance/node_modules/orientdb/lib/orientdb/connection/manager.js:218:21) 
at Socket.<anonymous> (/home/arpho/Projects/myBalance/node_modules/orientdb/lib/orientdb/connection/manager.js:167:14) 

當我嘗試在提交表單後訪問list_purchase,它會發生在post和get中。

這ISAN提取app.js

 app.set('port', process.env.PORT || 3000); 
    app.set('views', __dirname + '/views'); 
    app.set('view engine', 'jade'); 
    app.use(express.favicon()); 
    app.use(express.logger('dev')); 
    app.use(express.bodyParser()); 
    app.use(express.methodOverride()); 
    app.use(express.cookieParser('your secret here')); 
    app.use(express.session()); 
    app.use(app.router); 
    app.use(express.static(path.join(__dirname, 'public'))); 
    //app.get('/new_post', routes.new_post_form); 
    //app.post('/new_post', routes.new_post); 
    app.get('/list_purchase',routes.list_purchase) 
    app.post('/list_purchase',routes.filtered_list_purchase) 

這是我index.js的摘錄:

exports.filtered_list_purchase = function(res,req){ 
    debug('filtering') 
    debug(req.req.body) 
    range = req.req.body.range 
    aggr = req.req.body.aggr 
    var intervals = Aggregation.makeIntervals(Aggregation,range,aggr) 
    debug(intervals) 
    for(var i =0;i<intervals.length;i++){ 
    debug('dentro il for') 
    debug(intervals[i]) 
    //aggiungo agli items di intervals il campo query 
    var item = intervals[i] 
    var where = Aggregation.makeClausolaWhere(Aggregation,item) 
    intervals[i].query = "select sum(price) as sum from purchase "+where 
    intervals[i].inizio = Aggregation.getDate(Aggregation,intervals[i].inizio) 
    intervals[i].fine = Aggregation.getDate(Aggregation,intervals[i].fine) 
    } 
    debug(intervals) 
    var count = 0 
    function iterator(item,next){module.db.command(item.query,function(e,o){if(e) {return console.dir(e)} 
    delete item.query //cancello il campo per risparmiare banda 
    count += 1 
    if (o.length>0){item.subTotal = o[0].sum}else{item.subTotal = 0} 
    next(e,o)}) 
    } 
    async.each(intervals,iterator,function(err){if(err){return console.dir(err)} 
    res.render("aggregatedCostList",{ 
     aggregation:Aggregation.aggregation.name[aggr], 
     data:intervals 
    }) 
    }) 
} 

定義我的表單模板:

costList.jade

延伸聚集 嵌段含量 表 THEAD 第 b Acquisto 第 b來自Prezzo 第 b諾塔 第 B數據 - 在locals.purchases

 tr 
     th 
      a(href="/purchase/"+a['@rid']) 
      p #{a.purchase} 
     th 
      p #{a.price} 
     th 
      p #{a.nota} 
     th 
      p #{a.data} 
p ----------------------------------------------------------------------------------------------------------- 
p Totale: #{locals.totale} 
a(href="/new_purchase") aggiungi acquisto 

聚合每一個.jade:

extends layout 
block aggregation 
    form(action=locals.next,method="post") 
    p 
    label lasso temporale 
    input(name="range",type="text") 
    p 
     label aggregazione 
      select(name='aggr') 
       option(value='d') day 
       option(value='w') week 
       option(value='m') month 
       option(value='y') year 
    input(type="submit",value='aggrega') 

我的出現吧,我找不到錯誤,肯定是在我的代碼

回答

14
function(res,req) 

你的參數是倒退。

Express通過請求,然後是響應。

+1

...而且你應該用一個'req'替換'req.req'。 – Bergi

+1

感謝您的完整性檢查。在我的快速應用程序設置路線的一晚後,我認爲我有點堅果,直到我打這個答案。 –

相關問題