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

How to put html in a string in a key value pair for submission into a collection in meteor

本文关键字:提交 集合 meteor 字符串 html 键值对      更新时间:2023-09-26

我正在尝试在视频元素的 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