我在我的流星應用程序中有一個登錄頁面。我已經定製自己的登錄:登錄後才能加載數據流星
{{#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'模板? –