代码之家  ›  专栏  ›  技术社区  ›  jthomasbailey

Meteor-如何将动态生成的内容插入到集合中?

  •  0
  • jthomasbailey  · 技术社区  · 13 年前

    我是Meteor的新手,几乎不懂其中的任何一个,但假设我有一个名为mycollection的集合,它是在顶部声明的,所以它在客户端和服务器部分都可用:

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

    然后我有这样的东西:

    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();
    });
    
    
    };
    

    然后在我的模板中:

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

    我想做的是将在#heynow div中创建的“thisforchingthing”html保存到集合中,并发布给所有人。如果有一种方法可以让Meteor简单地观察dom的变化并保存它们,那就更好了。

    我 做 如果有区别的话,请卸载自动发布。暂停。

    2 回复  |  直到 13 年前
        1
  •  1
  •   L.T    13 年前

    客户端内模板

        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);
             });
           };
        }
    
        2
  •  0
  •   jthomasbailey    13 年前

    我在客户部分需要这样做:

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

    希望这能帮助到别人!