Javascript 如何将html放入键值对中的字符串中,以便提交到meteor中的集合中

Javascript 如何将html放入键值对中的字符串中,以便提交到meteor中的集合中,javascript,video,meteor,Javascript,Video,Meteor,我试图在视频元素的src值中使用变量,它是一个字符串本身,将被插入到集合中。我不仅仅是在集合中存储src值,因为如果没有视频src,我不希望输出空视频 我当前收到一个意外的令牌 'submit form': function(e) { e.preventDefault(); var videoSrc = $(e.target).find('[name=video]').val() var post = { title: $(e.target).find(

我试图在视频元素的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});
    });
  }
“提交表单”:函数(e){
e、 预防默认值();
var videoSrc=$(e.target).find('[name=video]').val()
var post={
标题:$(e.target).find('[name=title]').val(),
image:$(e.target).find('[name=image]').val(),
内容:$(e.target).find('[name=content]').val(),
视频:“
您的浏览器不支持视频标记。
"
};
Meteor.call('postInsert',post,函数(错误,结果){
//向用户显示错误并中止
如果(错误)
返回警报(错误原因);
会话更新(“imageId”,null);
会话更新(“imageKey”,null);
会话更新(“videoId”,空);
会话更新(“videoKey”,空);
go('postPage',{u id:result.\u id});
});
}

我假设这一行的结果是未定义的
视频:
您的浏览器不支持视频标记。
“

使用条件对象的好方法是将选择器设置为:

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
var选择器={};
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)
选择器。视频=”
您的浏览器不支持视频标记。
";
var post=选择器