How to use Meteor methods inside of a template helper

前端 未结 6 1372
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 12:05

How can I define a Meteor method which is also callable in a template helper?

I have these two files:

file: lib/test.js

Meteor.methods({
             


        
6条回答
  •  没有蜡笔的小新
    2020-11-22 12:47

    This is expected behavior. You are not using methods as they are intended.

    Your code defines a server method viewTest and a corresponding method stub on the client with the same name.

    Meteor.call('viewTest', 'Hello World.'); remotely calls viewTest on the server and in parallel runs the stub on the client.

    Regarding the return value of the stub please see the documentation here, in particular:

    On the client, the return value of a stub is ignored. Stubs are run for their side-effects: they are intended to simulate the result of what the server's method will do, but without waiting for the round trip delay.

    Regarding the return value of the server method please see the documentation here, in particular:

    On the client, if you do not pass a callback and you are not inside a stub, call will return undefined, and you will have no way to get the return value of the method. That is because the client doesn't have fibers, so there is not actually any way it can block on the remote execution of a method.

提交回复
热议问题