【问题标题】:Meteor's Iron:router: how to render template based on Session variable (cordovaReady)?Meteor's Iron:router: 如何根据 Session 变量 (cordovaReady) 渲染模板?
【发布时间】:2016-01-07 07:13:33
【问题描述】:

我在 Meteor 项目中使用 Iron:router + Cordova。

由于我的应用依赖于 Cordova 库,我需要等待 Cordova 准备好。

client/lib/init.js

Session.set('cordovaReady', false);
var initCordova = function() {

    /*
     * init filetransfer cordova plugin
     */
    var fileTransfer = new FileTransfer(),
        storageDataDirectory = cordova.file.dataDirectory;

    // make them global
    window.fileTransfer = fileTransfer;
    window.storageDataDirectory = storageDataDirectory;

    Session.set('cordovaReady', true);

};
initCordova();

shared/lib/routing.js

Router.configure({
    loadingTemplate: 'loading',
    layoutTemplate: 'common' 
});

Router.route('/config', {
    name:'config',
    template:'configuration',
    onBeforeAction: function(){
    // TODO: allow template rendering only once cordovaReady session variable is == true

    this.layout(null);
    this.render("configuration");
 }
})

client/app.js

Router.go('config');

如何等到 cordovaReady == true,然后路由到 /config

【问题讨论】:

    标签: cordova meteor iron-router


    【解决方案1】:

    我相信你应该可以做到:

    onBeforeAction: function(){
      if ( Session.get('cordovaReady') ) this.next();
      else this.render('loading');
    });
    

    假设您有一个名为 loading 的加载模板(例如:微调器)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-16
      • 2012-05-28
      • 2016-05-22
      • 2016-04-03
      • 2013-01-22
      • 2016-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多