【发布时间】:2014-05-24 17:51:33
【问题描述】:
我正在努力将数据从一个模板传递到另一个模板,并且考虑到它我想知道这是否是我的问题。我正在使用内置帐户系统,我添加了新用户和身份验证工作,当用户登录时,我将它们转发到新模板。我希望能够在该模板中使用他们的详细信息,但我正在努力找出最好的方法。
最初我以为我可以简单地使用:Router.go('userPage', {user:username});,它没有给出错误但不起作用。在我使用的模板中:<p>Welcome {{user}}</p>
使用{{> user}} 会引发'Can't find template, helper or data context key: username' 错误。
有什么想法吗?
编辑:忽略其余部分,重新启动 Meteor 服务器后,现在可以正常工作了。
认为我在这里有一个更大的问题,所以添加更多细节:
从表单中获取一些信息,然后根据结果进行路由:
Meteor.loginWithPassword(username, password, function(err) {
if (err) {
console.log('Logging in failed');
} else {
console.log('Logging in succeeded');
console.log(username);
Router.go('userPage');
}
});
然后我希望打开这个模板并传递刚刚登录的用户的数据:
<template name="userPage">
<div class="container">
<h1>Welcome {{username}}</h1>
</div>
<p>User Page</p>
</template>
如果我使用<p>Welcome {{currentUser.username}}</p>,我不会收到任何错误,但也不会收到名称。 Meteor.user().username 确实返回了一个名称,但我无法将其放入模板中。
【问题讨论】:
标签: meteor iron-router accounts