为什么这段代码似乎没有向Meteor.users.profile对象添加记录?
Why doesn't this code appear to add record to Meteor.users.profile object?
我试图创建一个包含配置文件表单的页面。所以我有一个'name'字段的文本框和一个添加它的按钮。
在我的客户端代码中,我有:
Template.profile.events({
'click input.add': function () {
Meteor.users.update({_id: this._id}, { $set:{"profile.name": profile_firstname}} )
}
});
在我的模板中我有:
<template name="profile">
{{#if currentUser}}
<div class="profile">
<h2>Profile</h2>
<input type="text" id="profile_firstname" />
<input type="button" class="add" value="Update Profile" />
</div>
{{/if}}
</template>
当我试图在控制台上找到用户时,我找不到配置文件。我还需要做什么才能使它工作?
尝试使用Meteor.userId()
而不是this._id
。
Template.profile.events({
'click input.add': function (e, t) {
var firstname = t.$('#profile_firstname').val();
Meteor.users.update({_id: Meteor.userId()}, { $set:{"profile.name": firstname}} );
}
});
在click处理程序中,this
为模板输入元素的数据上下文。或者,您也可以使用#with
设置上下文,这样您的原始代码就可以工作了。
<template name="profile">
{{#if currentUser}}
<div class="profile">
<h2>Profile</h2>
{{#with currentUser}}
<input type="text" id="profile_firstname" />
<input type="button" class="add" value="Update Profile" />
{{/with}}
</div>
{{/if}}
</template>
相关文章:
- Meteor如何接收HTTP请求
- Meteor-将选定窗体中的对象添加到集合中
- Meteor上的启动页面
- Meteor方法在客户端返回null,在客户端运行的相同方法返回正确的值
- Meteor-添加用户自定义字段的方法不起作用
- Meteor忘记了密码的实现
- 链接所有<a>Meteor
- 从客户端更新Meteor.users
- 子类化 Meteor.users() 以获得不同的用户类型
- 为什么 Meteor.users.findOne({用户名: “test”}) 返回一个对象,但用具有相同值的变量替换
- 将架构附加到 Meteor.users
- 如何启用帐户用户可编辑或如何删除或编辑Meteor.users()的用户
- 如何添加我自己的Meteor.users个人资料;使用aldeed自动成型和collection2
- 如何使用 Meteor.users.update 在特定案例对象中包含变量
- 为什么这段代码似乎没有向Meteor.users.profile对象添加记录?
- Meteor Users集合和Deps.自动运行的问题
- 向Meteor.users的配置文件部分添加字段
- 检查Meteor.users订阅是否已填充
- 后续:Meteor.users带有字符串参数
- Meteor,'/users/insert'已经定义