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の isan 抽出物です:

      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 に答える