TypeError:Object#<incomingmessage>没有方法'render'</incomingmessage>

时间:2013-10-02 17:13:37

标签: javascript node.js express

我正在使用node.js和express开发一个简单的应用程序,几乎一切都还可以,但是我收到了这个错误:

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中发生。

这是我 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 Nota          日            b数据           - 每个a in 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

aggregation.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')

对我来说是正确的,我找不到肯定在我的代码中的错误

1 个答案:

答案 0 :(得分:14)

function(res,req)

你的参数是倒退的。

Express传递请求,然后是响应。