【问题标题】:How to insert data in ground.db in meteor when offline离线时如何在流星的ground.db中插入数据
【发布时间】:2017-12-15 21:15:18
【问题描述】:

我有一个完整的流星应用程序,但现在我想让它离线,所以我安装了 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.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
        });        
    }
});

在客户端,消息的调用方式如下: 从“流星/流星”导入{流星}

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% 离线

谢谢;)

【问题讨论】:

  • 在您的客户端上,您正在制作 Meteor.call(),这是一种在服务器上调用方法的方式(但当您离线时服务器不存在)。如果你想让这些方法离线可用,你需要meteor groundmethods github.com/GroundMeteor/Meteor-groundmethods

标签: javascript mongodb cordova meteor grounddb


【解决方案1】:

自从我使用 Ground:db 已经有一段时间了,但我认为你缺少的是……

首先,您可能只想要 Cordova 上的接地集合,所以

if(Meteor.isCordova) {
  Ground.Collection(Gebiete);
  Ground.Collection(Straßen);
  Ground.Collection(Nummern);
}

然后你需要使用Groundmethods 来存储你的方法调用。所以在定义方法之后:

Meteor.methods({
  'neuesGebiet': function(...) {
    ...
  }
});

if( Meteor.isClient ) {
  Ground.methodResume([
    'neuesGebiet'
  ]);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多