【发布时间】:2017-03-22 07:28:58
【问题描述】:
我正在尝试使用自动表单来更新集合中的数组对象。该集合包含大量信息,但是使用此表格我只想更新职业历史。我希望能够使用引导列控制表单的布局。为此,我需要能够独立引用careerHistory.$.company 和careerHistory.$.title。目前,我只能通过引用name="careerHistory" 来呈现表单。每当我尝试引用数组中的特定字段时,表单都不会打印。
路径:Profile.js
import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';
import { addressSchema } from '../../sharedSchemas/addressSchema.js';
SimpleSchema.extendOptions(['autoform']);
export const Profile = new Mongo.Collection('Profile');
Profile.allow({
insert: function(userId, doc) {
return !!userId;
},
update: function(userId, doc) {
return !!userId;
},
remove: function(userId, doc) {
return !!userId;
}
});
Schemas.Profile = new SimpleSchema({
userId: {
type: String,
optional: true
},
'careerHistory.$': Object,
'careerHistory.$.company': {
type: String,
optional: false,
},
'careerHistory.$.title': {
type: String,
optional: true,
});
Profile.attachSchema(Schemas.Profile);
路径:Profile.html
{{#autoForm collection=profileCollection doc=profile id="candidateCareerHistory" type="update"}}
{{> afArrayField name="careerHistory"}}
{{/autoForm}}
路径:Profile.js
profile() {
return Profile.findOne({userId: Meteor.userId()});
},
profileCollection() {
return Profile;
}
【问题讨论】:
标签: meteor meteor-autoform simple-schema