我使用summernote文本编辑器,当新条目进入数据库时,codeview工作正常。
条目如下所示:
{
"_id" : "c7PMjuqnAfNbpdC2T",
"title" : "Testing fontsize",
"description" : "<p><span style=\"font-size: 12px;\">asdadsasd</span></p><p><span style=\"font-size: 18px;\" class=\"\">asdasda</span></p><p><span style=\"font-size: 24px;\" class=\"\">asdasdsad</span></p><p><br></p>",
"cleanDescription" : "asdadsasdasdasdaasdasdsad",
"category" : "strategy",
"keywords" : [
"rss",
"fml"
],
"type" : "news",
"createdAt" : "Mon, 01 Aug 2016 09:00:12 +0200",
"publishedAt" : "Mon, 01 Aug 2016 09:00:12 +0200",
"publishedRawFormat" : ISODate("2016-08-01T19:00:12.080Z"),
"coverImageId" : "Wt5cB8cuHu7BWSh7h",
"attachmentId" : "vJYGX8rpXaKighgL2"
}
我的JS档案:
Template.adminNewsEventsEdit.helpers({
//...
afterLoad: function(){ //Fire the code when the page is full loaded.
Meteor.setTimeout(function(){ //Latency compensation 0.8sec
$('#description').summernote({
height: 200,
toolbar: [
// [groupName, [list of button]]
['style', ['style']],
['font', ['bold', 'italic', 'underline', 'clear']],
//['fontname', ['fontname']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['height', ['height']],
['table', ['table']],
['insert', ['link', 'hr']], // 'picture', is tooked out
['view', ['fullscreen', 'codeview']],
['help', ['help']]
]
});
//...
html:
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="title" class="col-sm-2 control-label">Title</label>
<div class="col-sm-10">
<input type="text" class="form-control" value="{{title}}" id="title" name="title" placeholder="Enter Title">
</div>
</div>
<div class="form-group">
<label for="description" class="col-sm-2 control-label">Description</label>
<div class="col-sm-10">
<div name="description" id="description">
{{{description}}}
</div>
</div>
</div>
...
整个代码可以在这里找到: https://github.com/OpenStratNet/OSN/tree/master/client/templates/admin
谢谢!