jthomasbailey
jthomasbailey

Reputation: 410

Meteor - How to insert dynamically generated content into a collection?

I'm new to Meteor and barely understand any of it but let's say I have a collection called mycollection, declared way up top so it's available in both the client and server section:

mycollection = new Meteor.Collection('MyDumbCollection');

And then I have something like this:

if (Meteor.isClient) {  


Deps.autorun(function() {
    Meteor.subscribe('mycollectionSubscription');
});



Template.myshittytemplate.rendered = function() {

$("#heynow").prepend(shitfuck).dosomething(); 
godammit = thisfuckingthing;
//paraphrasing


mycollection.insert({thing1: thisfuckingthing});

  };


}





if (Meteor.isServer) {


 Meteor.publish('mycollectionSubscription', function () {
return mycollection.find();
});


};

And then in my template:

<template name="myshittytemplate">
<div id ="heynow">
{{#each mycollection}}
{{{thing1}}}
{{/each}}
</div>
</template>

What I'm trying to do is have the 'thisfuckingthing' html that's created in the #heynow div saved to the collection and published to everybody. If there's a way to make Meteor simply observe changes to the dom and save them, that's even better.

I do have autopublish uninstalled, if that makes a difference. Halp.

Upvotes: 0

Views: 240

Answers (2)

L.T
L.T

Reputation: 2589

In client Template

    Template.myshittytemplate.mycollection = function() {
       return mycollection.find({}).fetch(); 
     };

    Template.myshittytemplate.rendered = function() {
       $(function(){
         $("#heynow").prepend(shitfuck).dosomething(); 
         godammit = thisfuckingthing;
        //paraphrasing
         mycollection.insert({thing1: thisfuckingthing},function(err,_id){
                   if(err){
                      console.log(err);
                      return;
                   });
                   console.log(_id);
         });
       };
    }

Upvotes: 1

jthomasbailey
jthomasbailey

Reputation: 410

I needed this in the Client part:

 Template.myshittytemplate.mycollection = function() {
 return mycollection.find(); 
 };

Hopes this helps somebody!

Upvotes: 0

Related Questions