TypeError:对象#<serverresponse>的属性“locals”不是函数

时间:2015-06-26 21:30:43

标签: javascript node.js express

我正在使用github项目来构建聊天,但使用快递3x有点过时了。

代码尝试将一些数据传递到req.locals对象,注释掉的代码就是我所做的但它没有保存,所以它在我的io.sockets.on('connection')函数中不起作用。

我正在尝试使用该对象来获取有关房间和内部用户的一些信息。

/*
 * Enter to a room
 */

exports.enterRoom = function(req, res, room, users, rooms, status){
  res.locals.room = room;
  res.locals.rooms = rooms;
  res.locals.user.nickname = req.user.username;
  res.locals.user.provider = req.user.provider;
  res.locals.user.status = status;
  res.locals.users_list = users;

  // res.locals({
  //   room: room,
  //   rooms: rooms,
  //   user: {
  //     nickname: req.user.username,
  //     provider: req.user.provider,
  //     status: status
  //   },
  //   users_list: users
  // });

  console.log(res.locals);
  res.render('room');
};

1 个答案:

答案 0 :(得分:1)

您收到错误是因为您尝试将res.locals作为函数调用:

 res.locals() // this executes a function

当它看起来不是。我不知道你要做什么,但这可能不是解决问题的方法。