2017-01-20 36 views
0

meteor.js等待Web服務調用時如何顯示進度加載器?在等待mongo集合中的數據時,我一直使用鐵路路由器來顯示進度,但現在我面臨的數據來源略有不同。所以,如果這是你的想法,隨時給我一個鐵路由器解決方案。任何想法都歡迎。 如果你有興趣在我的代碼是如下:meteor.js等待Web服務調用時,如何顯示進度加載器/微調器?

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模板。所以沒有什麼是石制的。哦,如果你有一個你以前解決過的類似例子,請隨時解釋你是如何解決它的。謝謝

回答

0

假設你想顯示在您mentionned模板裝載機,我會嘗試使用反應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) 
       } 
      }))); 


     } 
    }); 
}); 

}

而且在你的模板顯示一個gif/loader,而is_loaded是錯誤的。你可以在模板的助手中以template.instance()。is_loaded.get()方式訪問is_loaded。

+0

Mathieu K,不幸的是你的建議不起作用,因爲is_loaded不會保留在頁面加載之間的模板中,並且不能像更新頁面加載之間的html字段那樣更新,除非我缺少一些東西。所以我看到它的方式並沒有限制在confirmWeather模板上進行方法調用,那麼可以將該邏輯移動到showFocust模板,在這種情況下,您可以立即路由到模板。任何接受者? –

+0

Mathieu K.工作之後,你的建議讓我找到了解決辦法。我碰到這個線程http://stackoverflow.com/questions/30546486/in-plain-english-what-does-tracker-autorun-do。謝謝。 –

+0

哦,你的功夫很強。 –

相關問題