如何在 meteor.js 等待网络服务调用时显示进度加载器/微调器?

How can I display a progress loader/ spinner while meteor.js waits for a web service call?

如何在 meteor.js 等待 Web 服务调用时显示进度加载程序?在等待来自 mongo 集合的数据时,我一直在使用 iron router 来显示进度,但现在我面临着稍微不同的数据源。因此,如果您有此想法,请随时给我一个铁路由器解决方案。欢迎任何想法。 如果您对我的代码感兴趣,它如下:

    if (Meteor.isClient) {
    Template.confirmWeather.onRendered(function(){
        var validator = $('.confirmWeatherAndGoToMessage').validate({
            submitHandler: function(event){
    Meteor.bindEnvironment(Meteor.call('testWeather',Meteor.bindEnvironment(function(error,result)
                {
                    if (error)
                    {
                        console.log(error.message)
                    }
                    else
                    {
                        var userId = Meteor.userId();
                        var user = Meteor.users.findOne({_id: userId});
                        if (user.testData)
                        {
                            Router.go('showFocust');
                        }
                        else
                        {
                            Router.go('showError');
                        }
                    }
                })));


            }
        });
    });

}

请注意,方法调用可以移至 showFocust 模板。所以没有什么是一成不变的。哦,如果你有一个你之前解决过的类似例子,请随时解释你是如何解决它的。谢谢

假设您尝试在您提到的模板中显示加载程序,我会尝试像这样使用反应性变量和自动运行:

if (Meteor.isClient) {
Template.confirmWeather.onRendered(function(){
    var instance = this;
    instance.is_loaded = new ReactiveVar(false);

    var validator = $('.confirmWeatherAndGoToMessage').validate({
        submitHandler: function(event){
Meteor.bindEnvironment(Meteor.call('testWeather',Meteor.bindEnvironment(function(error,result)
            {
                if (error)
                {
                    console.log(error.message)
                }
                else
                {
                    var userId = Meteor.userId();
                    var user = Meteor.users.findOne({_id: userId});
                    if (user.testData)
                    {
                        Router.go('showFocust');
                    }
                    else
                    {
                        Router.go('showError');
                    }

                    instance.is_loaded.set(true)
                }
            })));


        }
    });
});

}

并且在您的模板中显示 gif/loader 而 is_loaded 为假。您可以在模板的帮助程序中访问 is_loaded 作为 Template.instance().is_loaded.get().