【问题标题】:Using summernote with meteor (Discover Meteor)将summernote与流星一起使用(发现流星)
【发布时间】:2014-11-22 17:12:07
【问题描述】:

所以,我一直在使用 Discover Meteor,但遇到了问题。

我正在尝试将 Summernote 中输入的内容插入到 mongo 中,但我遇到了一些问题。

post_submit.html

<div class="form-group {{errorClass 'content'}}">
     <textarea class="form-control" name="content" id="summernote"></textarea>               
</div>

post_submit.js

var post = {
  url: checkURLPrefix( $(e.target).find('[name=url]').val() ),
  title: $(e.target).find('[name=title]').val(),
  content: $(e.target).find('[name=content]').val()
};

lib/posts.js(提交时会说 Match Failed 错误)

meteor.methods({
  postInsert: function(postAttributes) {
    check(this.userId, String);
    check(postAttributes, {
      title: String,
      url: String,
      content: function(content){$('[name=content]').html($('#summernote').code());}  
    });

我已经尝试content: String 将数据输入到 mongo 中。它可以工作,但是当我尝试在 post_page.html 文件中加载 {{content}} 时,它只会显示未渲染的 HTML 代码。 {{{content}}} 会显示正确呈现的内容,但会破坏基于投票的排序系统的功能。

我真的迷路了,我希望我能尽快找到解决方案。

提前谢谢你!

EDIT1:这是我的 post_page.html 以及我在插入内容时看到的内容:字符串并使用 {{content}} 加载

<template name="postPage">
  {{> postItem}}

    <div class="col-md-12" style="background:blue;">

        {{content}}

    </div>    

  <ul class="comments">
    {{#each comments}}
      {{> commentItem}}
    {{/each}}
  </ul>

  {{#if currentUser}}
    {{> commentSubmit}}
  {{else}}
    <p>Please log in to leave a comment.</p>
  {{/if}}
</template>

http://i.imgur.com/Fm0CXAN.png

【问题讨论】:

    标签: javascript jquery html mongodb meteor


    【解决方案1】:

    首先:您应该在div 中使用summernote,而不是textarea

    而在post_submit.js 中,你必须这样:

    var post = {
        ...
        content: $(e.target).find('#summernote').code()
    };
    

    在您的post_page.html 中使用三方括号,因为它是 HTML。

    <div class="col-md-12" style="background:blue;">
        {{{content}}}
    </div>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-02
      • 2023-03-11
      • 2017-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多