在流星 js 中显示来自 mongodb 的 Summernote 内容时出错

Posted

技术标签:

【中文标题】在流星 js 中显示来自 mongodb 的 Summernote 内容时出错【英文标题】:Error while displaying Summernote content from mongodb in meteor js 【发布时间】:2018-10-14 20:00:33 【问题描述】:

我正在制作简单的博客应用程序,但在从 db 加载时出现错误

模板

<template name="view">
 <div>
          summernote 
 </div>
</template>

从 Mongodb 显示.....

  <div class="container">
> editor

  #each post  > view /each

main.js

if (Meteor.isClient) 

  Template.body.helpers(

    post: function () 

      return Post.find();
    
  );

  Template.editor.onRendered(function () 
    $(document).ready(function () 
      $('#summernote').summernote(

        height: 300
      );
    );
  );

  Template.editor.events(
    'click #saveContent': function (e) 

      e.preventDefault();

      var summernote = $('#summernote').summernote('code');

      Meteor.call('posts.insert', summernote);
    
  );

lib.js

import  Meteor  from 'meteor/meteor';
import  check  from 'meteor/check';
import  Mongo  from 'meteor/mongo';

export const Post = new Mongo.Collection('posts');

Meteor.methods(

  'posts.insert'(summernote) 

    check(summernote, String);
    Post.insert(
      summernote,
      createdAt: new Date()
    );
    console.log(summernote);
  
);

我收到以下错误

队列任务中的异常:Spacebars.include@http://localhost:3000/packages/spacebars.js?hash=547cf8e466d1d52603d19bd5f48fb5df184fd237:48:13 template.main.js/http://localhost:3000/app/app.js?hash=47d4ac698c02f59520602a8871b3d5485a3a5b26:31:19 doRender@http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:2086:20 viewAutorun/http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:1934:18 Template._withTemplateInstanceFunc@http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3744:12 查看自动运行/http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:1932:14 Blaze._withCurrentView@http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:2271:12 查看自动运行@http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:1931:12 Tracker.Computation.prototype._compute@http://localhost:3000/packages/tracker.js?hash=0e8b5c18d543a28ce43b2f183c26b49ee62196af:339:5 Tracker.Computation@http://localhost:3000/packages/tracker.js?hash=0e8b5c18d543a28ce43b2f183c26b49ee62196af:229:5 Tracker.autorun@http://localhost:3000/packages/tracker.js?hash=0e8b5c18d543a28ce43b2f183c26b49ee62196af:613:11 Blaze.View.prototype.autorun@http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:1944:14 Blaze._materializeView/http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:2080:5 Tracker.nonreactive@http://localhost:3000/packages/tracker.js?hash=0e8b5c18d543a28ce43b2f183c26b49ee62196af:640:12 Blaze._materializeView@http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:2079:3 添加在/http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:2851:25 Tracker.nonreactive@http://localhost:3000/packages/tracker.js?hash=0e8b5c18d543a28ce43b2f183c26b49ee62196af:640:12 添加在@http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:2824:9 添加在@http://localhost:3000/packages/observe-sequence.js?hash=5da2e60ce61e074a6463979f3992dd5bac41b43d:373:9 添加之前@http://localhost:3000/packages/minimongo.js?hash=9d4bb4b714acae5bd3d70f96bb3803e155b57e38:3372:11 添加之前@http://localhost:3000/packages/minimongo.js?hash=9d4bb4b714acae5bd3d70f96bb3803e155b57e38:2836:13 wrapCallback/http://localhost:3000/packages/minimongo.js?hash=9d4bb4b714acae5bd3d70f96bb3803e155b57e38:1827:13 SQp.runTask@http://localhost:3000/packages/meteor.js?hash=c9a34f92f28ede5a42eac467d3fa1763b624436a:782:9 SQp.flush@http://localhost:3000/packages/meteor.js?hash=c9a34f92f28ede5a42eac467d3fa1763b624436a:811:3 SQp.drain@http://localhost:3000/packages/meteor.js?hash=c9a34f92f28ede5a42eac467d3fa1763b624436a:820:5 resumeObservers@http://localhost:3000/packages/minimongo.js?hash=9d4bb4b714acae5bd3d70f96bb3803e155b57e38:2438:7 endUpdate@http://localhost:3000/packages/mongo.js?hash=7dae0d2bbf4992c92bbb005435b6ee27a23d13b2:339:9 registerStore/http://localhost:3000/packages/ddp-client.js?hash=a547928b29e722e419948bbc25e954f2c268a1c3:631:20 _performWrites/http://localhost:3000/packages/ddp-client.js?hash=a547928b29e722e419948bbc25e954f2c268a1c3:1630:11 _performWrites@http://localhost:3000/packages/ddp-client.js?hash=a547928b29e722e419948bbc25e954f2c268a1c3:1629:9 _flushBufferedWrites@http://localhost:3000/packages/ddp-client.js?hash=a547928b29e722e419948bbc25e954f2c268a1c3:1587:7 _livedata_data@http://localhost:3000/packages/ddp-client.js?hash=a547928b29e722e419948bbc25e954f2c268a1c3:1548:9 onMessage@http://localhost:3000/packages/ddp-client.js?hash=a547928b29e722e419948bbc25e954f2c268a1c3:2153:9 _launchConnection/this.socket.onmessage/http://localhost:3000/packages/socket-stream-client.js?hash=55bf4fc2eb00d41c79827f8ec3b3949bbec01ce1:261:13 forEachCallback@http://localhost:3000/packages/socket-stream-client.js?hash=55bf4fc2eb00d41c79827f8ec3b3949bbec01ce1:355:7 _launchConnection/this.socket.onmessage@http://localhost:3000/packages/socket-stream-client.js?hash=55bf4fc2eb00d41c79827f8ec3b3949bbec01ce1:260:11 sockjs-0.3.4.js/SockJShttp://localhost:3000/packages/socket-stream-client.js?hash=55bf4fc2eb00d41c79827f8ec3b3949bbec01ce1:645:7 sockjs-0.3.4.js/SockJShttp://localhost:3000/packages/socket-stream-client.js?hash=55bf4fc2eb00d41c79827f8ec3b3949bbec01ce1:1824:5 sockjs-0.3.4.js/SockJShttp://localhost:3000/packages/socket-stream-client.js?hash=55bf4fc2eb00d41c79827f8ec3b3949bbec01ce1:1890:11 sockjs-0.3.4.js/SockJShttp://localhost:3000/packages/socket-stream-client.js?hash=55bf4fc2eb00d41c79827f8ec3b3949bbec01ce1:2048:7 流星.js:992:11

【问题讨论】:

each 块在 &lt;template&gt; 标记之外做什么? 你在哪里定义'summernote'?可以展示一下吗? 我已经更新了代码@MasterAM @GokhanKaradag,哪一个 summernote ??? 当您在空格键中使用三方括号时,您应该小心,因为您在其中插入了原始 html 【参考方案1】:

尝试你的方法

Post.insert(
      summernote: summernote,
      createdAt: new Date()
    );

【讨论】:

以上是关于在流星 js 中显示来自 mongodb 的 Summernote 内容时出错的主要内容,如果未能解决你的问题,请参考以下文章

开发期间的流星自定义mongodb

在通过流星的发布方法提供数据之前从另一个 mongodb 集合中添加信息

Node.js - Http get 不会在 Postman 或浏览器中显示来自 MongoDb 查询的数据

使用实习生 js 和流星

如何在不同的机器上连接流星和 mongoDB

summernote 编辑器如何用流星存储在 mongodb 中