mongo dbコレクションに文字列の配列を挿入しようとしています。メテオコレクションの配列に文字列を挿入する
そのエラーinsert failed: Error: Address must be a string
EDIT
私はのCCや参加者のためのダイナミックなフォームフィールドを生成し、そして配列にこれらの値を保存する必要が午前を考え出します。ここ
jQueryのスニペット:
$(function(){
$(document).on('focus', 'div.form-group-options div.input-group-option:last-child input', function(){
var sInputGroupHtml = $(this).parent().html();
var sInputGroupClasses = $(this).parent().attr('class');
$(this).parent().parent().append('<div class="'+sInputGroupClasses+'">'+sInputGroupHtml+'</div>');
});
$(document).on('click', 'div.form-group-options .input-group-addon-remove', function(){
$(this).parent().remove();
});
});
HTML:
<form class="row form-horizontal newMeeting">
<div class="form-group form-group-options col-xs-11 col-md-3" id="cc">
<div class="input-group input-group-option col-xs-12">
<input type="text" name="option[]" class="form-control" id="cc" placeholder="CCs">
<span class="input-group-addon input-group-addon-remove">
<span class="glyphicon glyphicon-remove"></span>
</span>
</div>
</div>
<div class="form-group form-group-options col-xs-11 col-md-3">
<div class="input-group input-group-option col-xs-12">
<input type="text" class="form-control" id="attendees" placeholder="Attendees">
<span class="input-group-addon input-group-addon-remove">
<span class="glyphicon glyphicon-remove"></span>
</span>
</div>
</div>
<div class="row no-print">
<div class="col-xs-12">
<input type="submit" value="Save" class="btn btn-primary pull-right">
</div>
</div>
</form>
私のスキーマ:
Emails = new Mongo.Collection('emails');
EmailSchema = new SimpleSchema({
"attendeesEmail": {
type: [Object],
optional: true
},
"attendeesEmail.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email
},
ccEmails: {
type: [Object],
optional: true
},
"ccEmails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email
}
});
Emails.attachSchema(EmailSchema);
イベント:
Template.form.events({
'submit .newMeeting': function(event) {
var cc = $('#cc').serializeArray();
var attendees = $('#attendees').serializeArray();
});
インサート:
Emails.insert({
attendeesEmail: [{address: attendees}],
ccEmails: [{address: cc }]
});
console.log(attendees);
プリント[Object]
エラーメッセージがinsert failed: Error: 0 must be a string
は、私はいくつかのソリューションを試みたが、それは働いて得ることができなかったと言い、任意の提案をいただければ幸いです。
データはまず、空の配列としての提案のための –