在 Meteor 中构建协作应用程序。我在将用户添加到会话时遇到问题。当我调用我的方法“addUserToSession”并传递相关 ID 时,我收到此错误。
Exception while simulating the effect of invoking 'addUserToSession' TypeError: Cannot read property 'editors' of undefined(…) TypeError: Cannot read property 'editors' of undefined
我希望这发生;
- 用户 A 开始一个会话。
- 将链接发送给用户 B
- 用户 B 转到 URL
- 用户 B 将其 ID 添加到 mongo 的会话记录中
- 客户端获取记录中的 JSON 并更新 DOM 内容。
我认为这可能与我订阅数据库的方式有关。任何帮助都会很棒!
路由器.js
//if hit a URL with an ID
//set id session var and render sessionGrid
FlowRouter.route('/tides/:_id', {
name: 'oceanSession',
subscriptions: function(params) {
console.log("subscribe to sessions");
Meteor.subscribe('sessions');
Meteor.subscribe('myCollabs');
},
action: function(params) {
Session.set('id', params._id);
Meteor.call("addUserToSession", Meteor.userId(),Session.get('id'));
//console.log('session id set ' + Session.get('id'));
BlazeLayout.render('main', {
stuff: "sessionGrid"
})
}
});
共享/main.js
addUserToSession:function(userId, sessionId){
console.log(userId + " to be added to " + sessionId);
var editorArray = Sessions.findOne(sessionId)["editors"];
console.log(editorArray);
//Sessions.update({_id: sessionId}, {$push:{editors:userId}});
}
这不正常,控制台得到
Exception while simulating the effect of invoking 'addUserToSession' TypeError: Cannot read property 'completed' of undefined(…) TypeError: Cannot read property 'completed' of undefined