Javascript 脱机时如何在meteor中的ground.db中插入数据
我有一个完全工作的meteor应用程序,但现在我想让它离线,所以我安装了ground:db和appcache这是我的包文件:Javascript 脱机时如何在meteor中的ground.db中插入数据,javascript,mongodb,cordova,meteor,grounddb,Javascript,Mongodb,Cordova,Meteor,Grounddb,我有一个完全工作的meteor应用程序,但现在我想让它离线,所以我安装了ground:db和appcache这是我的包文件: ... ground:db appcache ground:localstorage 然后我将我的收藏更改为: Gebiete = new Mongo.Collection('gebiete'); Straßen = new Mongo.Collection('straßen'); Nummern = new Mongo.Collection('nummern');
...
ground:db
appcache
ground:localstorage
然后我将我的收藏更改为:
Gebiete = new Mongo.Collection('gebiete');
Straßen = new Mongo.Collection('straßen');
Nummern = new Mongo.Collection('nummern');
Ground.Collection(Gebiete);
Ground.Collection(Straßen);
Ground.Collection(Nummern);
现在,当应用程序在线时,我可以插入数据,然后断开应用程序并重新启动(cordova),数据不会丢失
但当我离线时,我想插入一些东西,但它不起作用;(.我认为我不必更改我的方法文件,但这里有一种方法可以确保它是否正确:
Meteor.methods({
neuesGebiet(Besitzer, Gebietsname, Gebietsnummer, Ort, Erstellungsdatum) {
Gebiete.insert({
Besitzer: Besitzer,
Gebietsname: Gebietsname,
Gebietsnummer: Gebietsnummer,
Ort: Ort,
Erstellungsdatum: Erstellungsdatum
});
}
});
在客户端上,消息的调用方式如下:
从“Meteor/Meteor”导入{Meteor}
Template.neuesGebietErstellen.onCreated(function () {
this.subscribe('gebiete');
});
Template.neuesGebietErstellen.events({
"submit .add-Gebiet": function (event) {
var Gebietsname = event.target.Gebietsname.value;
var Gebietsnummer = event.target.Gebietsnummer.value;
var Ort = event.target.Ort.value;
var Besitzer = Meteor.userId();
var Erstellungsdatum = new Date();
var Datum = Erstellungsdatum.toLocaleDateString();
Meteor.call('neuesGebiet', Besitzer, Gebietsname, Gebietsnummer, Ort, Datum)
FlowRouter.go('/');
return false;
}
});
请帮助我在脱机时插入数据,因为我希望它100%脱机
谢谢;)我已经有一段时间没有使用Ground:db了,但我认为您缺少的是 首先,你可能只想要Cordova的固定收藏,所以
if(Meteor.isCordova) {
Ground.Collection(Gebiete);
Ground.Collection(Straßen);
Ground.Collection(Nummern);
}
然后需要使用来存储方法调用。因此,在定义方法之后:
Meteor.methods({
'neuesGebiet': function(...) {
...
}
});
if( Meteor.isClient ) {
Ground.methodResume([
'neuesGebiet'
]);
}
在客户端上,您正在创建Meteor.call(),这是在服务器上调用方法的一种方式(但脱机时服务器不存在)。如果您想使meteor groundmethods脱机可用,则需要meteor groundmethods。