Data displaying as a object

I don’t want the data to display as a object: [object Object] when I search for a specific Title and click the view button; I want it to display readable data.

html and template:

  <title>blog</title>
</head>
<body>
  {{> blogName}}
</body>

<template name="blogName">
		<header class="main-header">
			<h1 class="main-heading">My Blog</h1>
		</header>
			<div class="main-content">
				<div class="postField">
						<input type="text" name="postTitle" id="Post_Title"  placeholder="Title" autofocus>
						<textarea type="text" name="postResponse" id="Post_Response" placeholder="Response"></textarea><br>
						<button type="submit" name="Submit" value="Submit" class="submitPost">Submit</button><br>
						<input type="text" name="View_Title" id="View_Title"  placeholder="View">
						<textarea type="text" placeholder="View Here" class="displayHere"></textarea>
						<button type="button" name="View" value="View" class="viewButton">View</button>
				</div>
			</div>

 </template>

Client Code:

Meteor.subscribe('theblogposts');
Template.blogName.events({
  'click .submitPost': function(event) {
    event.preventDefault();
    var postTitlevar = $('#Post_Title').val();
    var postResponsevar = $('#Post_Response').val();
    console.log(postTitlevar + postResponsevar);
    Meteor.call('insertBlogPost', postTitlevar, postResponsevar);
  },
  'click .viewButton': function() {
  var titleVar = $('#View_Title').val();
  var viewBlogVar = $(".postField .displayHere").val();
  console.log(titleVar);
  return $(".postField .displayHere").val(BlogLists.find(
      {
        title: titleVar
      }
    ))
  }
});

Server code:

Meteor.publish('theblogposts', function ()
  {
        return BlogLists.find({});
  }
);

Meteor.methods({
  'insertBlogPost': function (postTitlevar, postResponsevar) {
    BlogLists.insert({
      title: postTitlevar,
      response: postResponsevar
    });

  },
});

Database:

BlogLists = new Mongo.Collection('blogposts');

Change

return $(".postField .displayHere").val(BlogLists.find(
      {
        title: titleVar
      }
    ))
  }

to

 return $(".postField .displayHere").val(BlogLists.find**One**(
       {
         title: titleVar
       }
     )**.title**)
   }

BlogLists.find() returns a cursor while findOne returns the document
http://docs.meteor.com/#/full/find

.title to get the value from the returned object

1 Like

Thanks. The solution worked.

1 Like