【问题标题】:Method call not returning from event but will from console方法调用未从事件返回,但将从控制台返回
【发布时间】:2016-02-11 21:59:32
【问题描述】:

我有一个奇怪的问题,我无法弄清楚。我的模板事件句柄中有一个方法和一个方法调用。由于某种原因,该方法调用只能像 5 次中的 1 次一样工作,并且不会更新 DOM。当调用正常时,console.log(Session.get('getReportData')+ " from method call"); 将对象返回到控制台,但不返回到 DOM。

当我在控制台中手动设置变量并调用时:

Meteor.call('getReportData',startDate, finishDate, function(err, data) {
                console.log("is the call working at all??");
                if (err)
                    console.log(err);
                Session.set('getReportData', data);
                console.log(Session.get('getReportData')+ " from method call");
            });

我把所有东西都拿回来了,DOM 也更新了。

代码如下:

Method:

'getReportData': function(startDate, finishDate) {
        /*
        if (mingi check, mis annaks errorit?) {
            throw new Meteor.Error("no-data-found", "No data can be found for selected period");
        } */
        var reportData = ScrapReport.find({dateEntered: { $gte: startDate}, dateEntered: { $lte: finishDate}}).fetch();
        return reportData;
    }
Client:

Template.report.events({
    'click .btn': function(startDate, finishDate) {
        var startDate = $('#startDate').val();
        console.log(startDate + ' StartfromTheButton')
        var finishDate = $('#finishDate').val();
        console.log(finishDate + ' FinishfromTheButton')

        Meteor.call('getReportData',startDate, finishDate, function(err, data) {
            console.log("is the call working at all??");
            if (err)
                console.log(err);
            Session.set('getReportData', data);
            console.log(Session.get('getReportData')+ " from method call");
        });
    }
})

Template.reportData.helpers({
    'reportData': function () {
        return Session.get('getReportData');
    }
});

什么会导致这个问题?

  1. 不是每次都调用。
  2. 当它工作时,DOM 没有更新?

【问题讨论】:

    标签: meteor meteor-methods


    【解决方案1】:

    我在函数调用中缺少事件和event.preventDefault();

    【讨论】:

      猜你喜欢
      • 2018-06-24
      • 2020-08-13
      • 2021-01-08
      • 2013-02-25
      • 2023-03-09
      • 1970-01-01
      • 2012-10-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多