gpt4 book ai didi

javascript - 类型错误 : Object # has no method 'render'

转载 作者:行者123 更新时间:2023-11-30 06:59:22 85 4
gpt4 key购买 nike

我正在使用 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

扩展聚合 block 内容 table 头 日 b 收购 日 b普雷佐 日 b 备注 日 b 数据 - 在 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

聚合.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')

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

最佳答案

function(res,req)

你的参数是反的。

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

关于javascript - 类型错误 : Object #<IncomingMessage> has no method 'render' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19142801/

85 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com