Can't Get Collection Data to Display

I can’t see where I’m going wrong. The list of websites does’t display.

// shared code
Websites = new Mongo.Collection("websites");


if (Meteor.isClient){
   template
    Template.addSiteForm.events({
        button... you need to compete it
     'click #js-add-site':function(event){
         var url = $('#url_input').val();// get the form value using jquery...
         var site = {"url":url};
         console.log(url);
         
		  Websites.insert(site);
		 // console.log(site);
         return false;
		  
		  
     }
    });

    Template.siteList.helpers({
        'all_websites':function(){
            return Websites.find().fetch();
        },
    });

};

<head>
  <title>week_2_peer_assessment</title>
</head>

<body>
    <div class="container">
        <h1>Welcome to Site Ace!</h1>
        Fill in the form and click submit to add a site:
        {{>addSiteForm}}
        {{>siteList}}
    </div>
</body>

<template name="siteList">
    <h3>Sites you have added:</h3>
    <ul>
    {{#each all_websites}}
		 <li>{{site}}</li>
    {{/each}}
    </ul>
</template>

<template name="addSiteForm">
<div class="row">
  <div class="col-lg-6">
    <div class="input-group">
      <input type="text" id="url_input" class="form-control" placeholder="Enter website URL...">
      <span class="input-group-btn">
        <button class="btn btn-default" id="js-add-site" type="submit">Add!</button>
      </span>
    </div><!-- /input-group -->
  </div><!-- /.col-lg-6 -->
</div>
</template>

Assuming you are using the insecure package, which allows you to write directly from the client, and the autopublish package, which allows you to autosubscribe to all data, then I think your fix is here:

{{#each all_websites}}
  <li>{{url}}</li>
{{/each}}

When you’re looping through a .find() or a .find().fetch(), you need to ask for the props of the object.

1 Like

Putting the spacebars in an anchor tag like this

 <li><a href="">{{url}}</a></li>

then clicking the link in the browser seems just I refresh the browser instead of going to the link.

In your code snippet, it doesn’t appear that you’re setting the href…