我在我的流星应用程序中有一个登录页面。我已经定制自己的登录:登录后才能加载数据流星
{{#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 =函数()不加载在第一时间当我登录到应用程序。
有人可以解释我用流星加载的顺序吗? :)
我们可以看看'isLogged','index'和'login'是如何声明的吗?我的直觉是'isLogged'没有反应,因此改变它不会重新运行模板。 – Joseph
当然,我编辑了我的帖子:) – Ricklemer
您是否也定义了'header'模板? –