2015-10-05 74 views
2

我已经尝试了流星框架的博客,而插入它显示的值插入失败和方法未找到错误,我患了2小时请纠正代码并使其工作,在此先感谢流星:插入失败的方法找不到错误

这个JavaScript文件:

Testing = new Mongo.Collection('posts'); 

if (Meteor.isClient) { 

Template.postForm.events({ 
    "submit .post-form": function (event) { 

    // Prevent default browser form submit 
    event.preventDefault(); 

    // Get value from form element 
    var title = $('#title').val(); 
    var description = $('#description').val(); 


    // Insert a task into the collection 
    Testing.insert({ 
    title: title, 
    description: description 
    // current time 
    }); 

    // Clear form 
} 
    }); 
} 

HTML文件是:

<template name="postForm"> 
    <div class="row"> 
     <div class="col-md-12"> 
      <form role="form" class="post-form" id="submit"> 
       <div class="form-group"> 

        <label for="exampleInputEmail1"> 
         title 
        </label> 
        <input type="text" class="form-control" id="title" /> 
       </div> 
       <div class="form-group"> 

        <label for="exampleInputPassword1"> 
         description 
        </label> 
        <input type="text" class="form-control" id="description" /> 
       </div> 
       <div class="form-group"> 

        <label for="exampleInputFile"> 
         File input 
        </label> 
        <input type="file" id="exampleInputFile" /> 
        <p class="help-block"> 
         Example block-level help text here. 
        </p> 
       </div> 
       <button type="submit" class="btn btn-default"> 
        Submit 
       </button> 
      </form> 
     </div> 
    </div> 
</template> 

,我曾经尝试都

Testing = new Mongo.Collection('posts'); 

Testing = new Meteor.Collection('posts'); 

回答

1

终于让我找到我的朋友在Facebook上

我们需要把

Testing = new Mongo.Collection('posts'); 

lib文件夹

+0

有些人喜欢里面的解决方案将这个名称命名为“both”而不是“lib”,因为这使得它的pu rpose /功能更清晰。 –

+0

里面的lib文件夹?这是什么意思?请让你的答案清楚。在哪个文件中?你应该在哪里添加这一行? –

+0

在我的服务器启动代码中添加新的Mongo.Collection('posts')为我工作 – TheAppchemist