【发布时间】:2017-06-29 08:53:09
【问题描述】:
我是 Meteor 的新手,我正在尝试在我正在构建的应用程序中使用 SimpleSchema /Autoforms。当用户创建组时,他们会填写组名称、描述和位置(地址)。在幕后,他们被添加为组的第一个成员,地址将很快转换为 lat/lng 值。
当我尝试保存时,location 和 members[0] 是空对象。
架构:
Groups = new Mongo.Collection('groups');
Groups.attachSchema(new SimpleSchema({
groupName: {
type: String,
label: "Group Name",
max: 200
},
createdBy: {
type: String,
autoform: {
omit: true
}
},
members: {
type: [{
_id: {type: String},
firstName: {type: String},
lastName: {type: String}
}],
label: "Group Members",
autoform: {
omit: true
}
},
location: {
type: {
address: {type: String},
lat: {type: String},
lng: {type: String}
},
label: "Location"
},
description: {
type: String,
label: "Group Description",
max: 250,
optional: true
}
}));
插入表格:
Template.groupsList.events({
'submit form': function(e) {
console.log('submitting form..');
e.preventDefault();
var group = {
groupName: $(e.target).find('[name=groupName]').val(),
createdBy: Meteor.userId(),
members: [{
_id: Meteor.userId(),
firstName: Meteor.user().profile.firstName,
lastName: Meteor.user().profile.lastName
}],
location: setLocation($(e.target).find('[name=location]').val()),
description: $(e.target).find('[name=description]').val()
};
function setLocation(location) {
return {
location: location,
lat: 123,
lng: 123
};
}
console.log(group);
var groupId = Groups.insert(group);
Router.go('/group/' + groupId);
}
});
我在 Stack Overflow 上看到过一些类似的问题,但与手头的问题相比,数据似乎总是更加模糊。我错过了什么明显的东西吗?
【问题讨论】:
标签: meteor meteor-autoform simple-schema