我的Meteor.Call和方法存在问题。
我将console.log('test')
放在方法代码中。控制台显示它,我可以在集合中看到一个毫秒的新文档(然后它就消失了)。
可能是什么错误?
的客户机/ sidurEditor.js
Template.sidurEditor.helpers({
showForSadran: function() {
return ForSadranDrives.find({},{sort: {askedDate: 1, since: 1}});
}
LIB / methods.js
Meteor.methods ({
addNewDriveToSadranTable: function (askedDate, since, until, askedDrive, askedUser) {
console.log('click');
ForSadranDrives.insert({
askedDate: askedDate,
since: since,
until: until,
askedDrive: askedDrive,
driveCar: "chooseCar",
driveCarName: "car undefined",
driveDriver: "driver undefined",
askedUser: askedUser,
askedNickName: Session.get('nickName'),
onEditDriveRow: false
});
console.log('click2');
} });
收集/ collections.js
ForSadranDrives = new Mongo.Collection('forsadrandrives');
答案 0 :(得分:1)
错误是我在方法中写了一个Session ...我把它放在Meteor.call(...)作为参数,它运行得很好!!
感谢@masterAM的评论和答案
现在看起来像那样:
<强>的客户机/ navbar.js 强>
Meteor.call('addNewDriveToSadranTable',askedDate, since, until, askedDrive, askedUser, Session.get('nickName'));
<强> LIB / methods.js 强>
Meteor.methods ({
addNewDriveToSadranTable: function (askedDate, since, until, askedDrive, askedUser, askedNickName) {
console.log('click1');
ForSadranDrives.insert({
askedDate: askedDate,
since: since,
until: until,
askedDrive: askedDrive,
driveCar: "chooseCar",
driveCarName: "אין רכב מוגדר",
driveDriver: "אין נהג מוגדר",
askedUser: askedUser,
askedNickName: askedNickName,
onEditDriveRow: false
});
console.log('click2');
}});
答案 1 :(得分:0)
您看到的是Meteor的延迟补偿 - 记录被插入到本地数据库(minimongo)中,但在从服务器刷新数据库时消失。这很可能是因为您对数据的订阅丢失或者您的过滤器正在排除数据。
您可以使用命令
在mongo shell中查找记录进行检查meteor mongo
确保您的CD位于项目目录
中