【发布时间】:2017-09-11 02:09:34
【问题描述】:
我正在尝试使用以下代码将对象添加到作为集合条目中的键的对象数组中,但我收到了一个奇怪的响应“插入失败:错误:需要标题”。我在流星上使用简单的模式/自动形式。
以前有没有人遇到过这种情况(并有解决方案)?
Template.dashboard.events({
'click .requestinvite'(e,t) {
Posts.insert({ _id : $(e.currentTarget).attr('_id')},
{$push: { invitesRequested : {username : Meteor.userId()} }}
);
}
});
这是咖啡脚本中相关的简单模式
Schemas.Posts = new SimpleSchema
title:
type:String
max: 60
optional: true
content:
type: String
optional: false
autoform:
rows: 5
createdAt:
type: Date
autoValue: ->
if this.isInsert
new Date()
updatedAt:
type:Date
optional:true
autoValue: ->
if this.isUpdate
new Date()
invitesRequested:
type: [Object]
optional: true
defaultValue: []
owner:
type: String
regEx: SimpleSchema.RegEx.Id
autoValue: ->
if this.isInsert
Meteor.userId()
autoform:
options: ->
_.map Meteor.users.find().fetch(), (user)->
label: user.emails[0].address
value: user._id
【问题讨论】:
-
您的简单架构必须有一个必需的标题
-
是的,似乎简单的架构阻止了插入,您需要允许标题。
-
请在此处发布您的 SimpleSchema。提供足够的详细信息,以免我们在您的问题上浪费时间。
-
@AnkurSoni 在上面添加了相关的简单模式
标签: javascript meteor meteor-autoform simple-schema