About the book<Discover Meteor>,about inserting pictures


#1

Reference to posting function in book , I expand a bit : You can insert a picture when posting ( replaced “textarea” by an editable “DIV” ), this has been achieved.Now I don’t know how to handle the submit? The book was only publishing of text only, by “content: $( e. Target ).Find ( ‘[name=content]’ ). val ( )” that gets the post content, then display . now there are pictures, how to deal with it?Is there a method similar to .val ( ) that can get the entire contents of the DIV ( including images )?

The way of getting the post content now used,it is easy:
var post={
title:$(e.target).find(’[name=title]’).val(),
content:$(e.target).find(’[name=content]’).val(),
category:$(e.target).find(’[name=category]:checked’).val()
}


#2

You can get the contents of a div using innerHTML.


#3

Thank you,but it display html code :

My code:
var post={
title:$(e.target).find(’[name=title]’).val(),
content:document.getElementById(“content”).innerHTML,
category:$(e.target).find(’[name=category]:checked’).val()
}

Template.postContent.helpers(
{content:function(){
return this.content;
}
});

<template name="postContent">
 <div>{{content}}</div>
</template>

#4

You can use triple braces{{{content}}}, but you should always be careful when using them!!!

If the content is user-generated, then you will need a way to sanitize it so that malicious code can’t be inserted into a page that one of your users may visit.


#5

Thank you very much!! You really are a nice person.