如何将 html 放在键值对的字符串中,以便提交到 meteor 中的集合中
How to put html in a string in a key value pair for submission into a collection in meteor
我正在尝试在视频元素的 src 值内放置变量,该元素本身是一个将要插入到集合中的字符串。我不只是将 src 值存储在集合中,因为如果没有视频 src,我不希望输出空视频。
我目前收到一个意外的令牌。
'submit form': function(e) {
e.preventDefault();
var videoSrc = $(e.target).find('[name=video]').val()
var post = {
title: $(e.target).find('[name=title]').val(),
image: $(e.target).find('[name=image]').val(),
content: $(e.target).find('[name=content]').val(),
video: "<video width='320' height='240' preload='auto' >
<source src='"+ videoSrc +"' type='video/webm'>
Your browser does not support the video tag.
</video>"
};
Meteor.call('postInsert', post, function(error, result) {
// display the error to the user and abort
if (error)
return alert(error.reason);
Session.update("imageId", null);
Session.update("imageKey", null);
Session.update("videoId", null);
Session.update("videoKey", null);
Router.go('postPage', {_id: result._id});
});
}
我假设这条线的结果是未定义的video: "<video width='320' height='240' preload='auto' >
<source src='"+ videoSrc +"' type='video/webm'>
Your browser does not support the video tag.
</video>"
做条件对象的好主意是使选择器如下:
var selector={};
selector.title= $(e.target).find('[name=title]').val();
selector.image= $(e.target).find('[name=image]').val();
selector.content= $(e.target).find('[name=content]').val();
if(videoSrc)
selector.video= "<video width='320' height='240' preload='auto' >
<source src='"+ videoSrc +"' type='video/webm'>
Your browser does not support the video tag.
</video>";
var post=selector
相关文章:
- Javascript生成的表单未提交
- 将输入字段中的文本提交到我的数据库,同时将其添加到我的列表中
- 如何使jQuery插件函数可调用以供独立使用,而不在集合上操作
- HTML表单提交时未执行外部函数
- 在POST中将html表作为csv提交
- Meteor-将选定窗体中的对象添加到集合中
- 我应该使用Ng提交还是点击表格
- 我想使用模态通过php文件发送邮件,并且我希望在提交关闭后关闭pop
- 提交后保留下拉选择的值
- 主干集合重置和解析
- 键入最后一位数字后自动提交
- 使用数据上的角度更改设置集合的第一个元素的动画
- 为集合分配大量的模型弹药
- 阻止表单元素提交
- 如何使用backbone.js从集合中获取模型名称
- Asp.Net MVC 3 表单集合在提交后丢失数据
- 使用主干模型和集合提交 AJAX
- 如何将 html 放在键值对的字符串中,以便提交到 meteor 中的集合中
- 流星-表单提交时没有插入到集合中
- 尝试提交“按钮复选框”的集合