数据don't登录流星后加载
The data don't load after login meteor
我的Meteor应用程序中有一个登录页面。我已经自定义了我的登录名:
{{#if isLogged}}
{{>index}}
{{else}}
{{>login}}
{{/if}}
如果用户已登录,我将加载"索引"模板。
所以我成功地登录了一个用户,应用程序在"索引"上路由我,但没有加载集合。
例如,我有:
Template.listWorkspace.rendered = function () {
//some stuff
});
当我登录时,这不是老问题。我必须按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>
第2版:
这是用户工作空间的模板:
<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=函数()在我第一次登录应用程序时不会加载。
有人能告诉我装载流星的顺序吗?:)
这里有很多错误。首先,你不需要自己的助手来检查用户是否登录。根据文档,只需使用Meteor推荐的{{#if currentUser}}
即可。
其次,您有一个可供使用的模板系统。为什么不使用它来定义小部件在页面上的显示方式,而不是在rendered
函数中以编程方式插入DOM节点呢?为什么要使用async
?试着通过模板尽可能少地做所有可能的事情,然后加入帮助程序,只实现模板无法实现的目标。您通常也不需要深入研究Meteor中的回调和异步代码。
试着用流星重置命令重新设置你的项目我在重命名文件后遇到了类似的问题,现在用{{#if currentUser}}
助手对我有效。
相关文章:
- 用户登录时的流星事件
- 流星用户帐户和alanning流星角色-登录时检查角色
- 流星在登录后重新提交登录表
- 流星 - 添加带有熨斗的路由后无法提交用户.路由器到登录和注册表单
- 数据don't登录流星后加载
- 流星如何保存登录状态
- 执行流星重置时,登录用户的应用程序页面冻结
- 用户登录后流星重新渲染模板
- 解锁流星注销并登录
- 流星:谷歌登录不'不能在iphone/ipad上工作
- 简单的用户登录流星,这样安全吗
- 如果用户想访问特定的页面,需要在angular流星中进行登录验证,如何重定向到404页面
- 如何创建一个登录系统与流星
- 流星服务器无需登录即可插入数据
- 流星-在发布模板之前检查登录状态
- 流星登录通过第三方库
- 流星异步登录问题
- 流星路由器-我如何检测当前路由是否需要用户登录
- 流星账户-登录表单更改HTML删除下拉JS
- 流星有铁路由器和登录按钮