Javascript 在meteor.js等待web服务调用时,如何显示进度加载器/微调器?
在meteor.js等待web服务调用时,如何显示进度加载器?我一直在使用iron router显示进度,同时等待来自mongo collections的数据,但现在我面临的数据来源略有不同。所以,请随时给我一个铁路由器解决方案,如果这是你的想法。欢迎提出任何意见。 如果您对我的代码感兴趣,请参阅以下内容:Javascript 在meteor.js等待web服务调用时,如何显示进度加载器/微调器?,javascript,meteor,iron-router,Javascript,Meteor,Iron Router,在meteor.js等待web服务调用时,如何显示进度加载器?我一直在使用iron router显示进度,同时等待来自mongo collections的数据,但现在我面临的数据来源略有不同。所以,请随时给我一个铁路由器解决方案,如果这是你的想法。欢迎提出任何意见。 如果您对我的代码感兴趣,请参阅以下内容: if (Meteor.isClient) { Template.confirmWeather.onRendered(function(){ var valid
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模板。所以什么都不是石头铸的。哦,如果你有一个类似的例子,你以前解决过,请随意解释你是如何解决的。谢谢假设您试图在您提到的模板中显示加载程序,我会尝试使用反应式var和自动运行,如下所示:
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)
}
})));
}
});
});
}
在您的模板中,当加载为false时,显示gif/加载程序。您可以访问作为template.instance()加载到模板帮助程序中的is_。is_loaded.get()。Mathieu K,不幸的是,您的建议不起作用,因为is_loaded不会在页面加载之间保留在模板中,并且不能像在页面加载之间更新html字段一样进行更新,除非我遗漏了什么。因此,在我看来,您并不局限于对confirmWeather模板执行方法调用,该逻辑可以移动到showFocust模板,在这种情况下,您可以立即路由到该模板。有人接受吗?马修K.经过努力,你的建议使我找到了解决办法。我偶然发现了这条线。谢谢。哦,你的功夫很强。