我使用Simple Schema设置了我的集合:
SubLinkSchema = new SimpleSchema({ name: { type: String, label: 'Link Name', unique: false }, link: { type: String, regEx: SimpleSchema.RegEx.Url, label: 'Custom Link', optional: true, autoform: { class: 'sub-custom-link' } } }); LinkSchema = new SimpleSchema({ name: { type: String, label: 'Link Name', unique: false }, link: { type: String, regEx: SimpleSchema.RegEx.Url, label: 'Custom Link', optional: true, autoform: { class: 'main-custom-link' } }, subLinks: { optional: true, label: 'Sub Links', unique: false, type: [SubLinkSchema] } });
在这里,问题是,子链接没有获得ID.很难在没有id的情况下更新它们.那么,我如何为每个子链接(嵌入文档)生成唯一ID?
在SimpleSchema中使用autovalue字段
请参阅参考资料:https: //github.com/aldeed/meteor-collection2#autovalue
和例子:
subLinkID: { type: String, autoValue: function() { return Meteor.uuid(); } }