2013-11-22 19 views
0

我在我的流星应用程序中有一个登录页面。我已经定制自己的登录:登录后才能加载数据流星

{{#if isLogged}} 
    {{>index}} 
{{else}} 
    {{>login}} 
{{/if}} 

如果用户登录我打开“索引”模板。

因此,我记录一个成功的用户和应用程序路线我的“索引”,但没有集合被加载。

比如我有:

Template.listWorkspace.rendered = function() { 
      //some stuff 
    }); 

当我记录,这是不LAOD。我必须按F5键来载入我所有的数据。

编辑

这里是isLogged声明:

if(Meteor.isClient) { 
Template.indexLogin.helpers({ 
    isLogged : function() { 
     var indexIsLoggedUser = Meteor.user(); 
     return indexIsLoggedUser != null; 
    } 
}); 

}

这是该指数模板声明:

<template name="index"> 
{{>widgetWorkspace}} 
</template> 

<template name="widgetWorkspace"> 
{{>header}} 
    {{>workspace}} 
</template> 

<template name="workspace"> 
<div class="row"> 
    <!-- <button class="btn btn-default" id="add"><span class="glyphicon glyphicon-plus"></span>Add widget</button> --> 
    <button class="btn btn-success" id="editmode" data-i18n="btn.editMode"></button> 
    <button class="btn btn-warning" data-toggle="modal" data-target="#myModal" data-i18n="btn.addWidgets"><span class="glyphicon glyphicon-plus"></span></button>{{>bootstrapModal}} 

    <!-- <button class="btn btn-danger" id="addContainer"><span class="glyphicon glyphicon-plus"></span>Add Container</button> --> 
    <!--<button class="btn btn-primary" id="serialize">Serialize</button>--> 
</div> 
<br> 
<div id="widgetMainContainer"> 
    {{#each Widgets}} 
     {{>widget}} 
    {{/each}} 
</div> 
</template> 

EDIT2:

这是与用户的工作区中的模板:

<template name="listWorkspace"> 
<ul id="workspaces"></ul> 
</template> 

这是所呈现的一些JavaScript代码:

Template.listWorkspace.rendered = function() { 
    var headerWorkspaceUserLogged = Meteor.users.find({_id: Session.get('user_id')}).fetch(); 
    var headerWorkspaces = headerWorkspaceUserLogged[0].workspace; 

    if(headerWorkspaces == null || headerWorkspaces == undefined) { 
     console.log('empty'); 
    } 

    async.forEachSeries(headerWorkspaces, function(item, callback) { 
     var d = $('<li/>'); 
     d.attr('rel', item.id-1).addClass('workspace-mini').click(function() { 
      NProgress.start(); 
      $('#workspaces li').removeClass('workspaceSelected'); 
      $(this).addClass('workspaceSelected'); 
      var text = $('<div/>'); 
      text.addClass('workspaceText') 
        .text('workspace ' + (parseInt($(this).attr('rel'))+1)) 
        .appendTo($(this)) 
        .position({ my: 'center center', at: 'center center', of: $(window)}) 
        .fadeIn(function() { $(this).fadeOut(function() { $(this).remove; })}); 
      current_workspace = headerWorkspaces[parseInt($(this).attr('rel'))]; 
      current_workspace_number = parseInt($(this).attr('rel')); 
      Session.set('current_workspace_number', current_workspace_number+1); 
      Session.set('current_workspace', current_workspace); 
      //on selectionne le workspace dans la base Mongo en fonction du workspace selectionné 
      Meteor.call('updateIdSelectdWorkspace', Session.get('user_id'), Session.get('current_workspace').name); 
      NProgress.done(); 
     }); 
     $('#workspaces').append(d); 

     //Pour l'ajout d'un nouveau workspace on memorise l'id du dernier workspace 
     Session.set('i', item.id); 

     callback(); 
    }, function(err) { 
     console.log('done'); 
    }); 
    $('#workspaces').append('<div id="addWorkspace"><span class="glyphicon glyphicon-plus"></span></div>'); 
    $('#addWorkspace').css('float', 'right') 
     .css('margin-left', '5px') 
     .css('margin-top', '2px') 
     .css('cursor', 'pointer'); 
}; 

的Template.listWorkspace.rendered =函数()不加载在第一时间当我登录到应用程序。

有人可以解释我用流星加载的顺序吗? :)

+0

我们可以看看'isLogged','index'和'login'是如何声明的吗?我的直觉是'isLogged'没有反应,因此改变它不会重新运行模板。 – Joseph

+0

当然,我编辑了我的帖子:) – Ricklemer

+0

您是否也定义了'header'模板? –

回答

0

这里有很多事情不对。首先,你不需要你自己的帮手来检查用户是否登录。根据docs,只需使用Meteor的建议{{#if currentUser}}即可。其次,您可以使用模板系统。为什么不使用它来定义窗口小部件应该如何显示在页面上,而不是在您的rendered函数中以编程方式插入DOM节点?你为什么使用async?尝试通过尽可能少的模板尽可能地通过模板尽可能地完成任务,然后放入助手只是为了实现模板不能完成的任务。您通常也不需要深入Meteor的回调和异步代码。

+0

是的你好,现在我使用currentUser,我删除了异步循环,但是我的问题总是一样的。当我登录我的用户时,loginWithPassword不起作用,并且logginIn方法保持不变。 我必须编辑我的代码以重新加载页面... – Ricklemer

+0

流星中没有页面重新加载。 '{{#unit currentUser}} {{> yourLoginTemplate}} {{else}} {{> yourHomePageTemplate}} {{/除非}}'。 –

0

尝试重置您的项目与流星重置命令我重命名文件后有类似的问题,现在为我工作与{{#if currentUser}}助手。