2015-10-05 75 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