1

我正在使用 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 th b Acquisto th b Prezzo th b Nota th b Data - locals.purchases 中的每个 a

       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

聚合.玉:

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

对我来说似乎是对的,我找不到我的代码中肯定存在的错误

4

1 回答 1

14
function(res,req)

你的参数是倒退的。

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

于 2013-10-02T17:15:29.330 回答