[英]How to store tags from Bootstrap Tags Input field into my collection…?
I'm using the ajduke:bootstrap-tagsinput` package and I'm trying to store the array in: 我正在使用ajduke:bootstrap-tagsinput`包,并尝试将数组存储在:
$('#dealTags').tagsinput('items')
in my deals collection, but the value of: 在我的交易集合中,但以下各项的价值:
$(e.target).find('[name=dealTags]').val()
comes back as undefined. 返回未定义。 I'm a newbie to Meteor and Javascript, so sorry if this is a dumb question.
我是Meteor和Javascript的新手,如果这是一个愚蠢的问题,对不起。 Here is the form field:
这是表单字段:
<div class ="controls">
<input id="dealTags" type="text" class="form-control" value="" placeholder="Add some tags..." data-role="tagsinput">
</div>
And here I try to insert the data to my collection in the Template 在这里,我尝试将数据插入模板中的集合
var deal = {
dealTitle: $(e.target).find('[name=dealTitle]').val(),
venueName: $(e.target).find('[name=venueName]').val(),
when: $(e.target).find('[name=when]').val(),
dealTags: $(e.target).find('[name=dealTags]').val()
};
And my collection method doing the actual writing to DB 而我的收集方法实际上是在写数据库
Meteor.methods({
dealInsert: function(dealAttributes) {
check(Meteor.userId(), String);
check(dealAttributes, {
dealTitle: String,
venueName: String,
when: String,
dealTags: String
});
Thanks! 谢谢!
I think you need to use the select element instead of input to have val() return an array. 我认为您需要使用select元素而不是input来让val()返回数组。 (see documentation )
(请参阅文档 )
<div class ="controls">
<select multiple id="dealTags" type="text" class="form-control" value="" placeholder="Add some tags..." data-role="tagsinput" />
</div>
Another solution is to keep using the input element, but call .tagsinput('items') instead of val() 另一个解决方案是继续使用input元素,但是调用.tagsinput('items')而不是val()
var deal = {
dealTitle: $(e.target).find('[name=dealTitle]').val(),
venueName: $(e.target).find('[name=venueName]').val(),
when: $(e.target).find('[name=when]').val(),
dealTags: $(e.target).find('[name=dealTags]').tagsinput('items')
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.