我已经尝试了一个带有meteor框架的博客,同时插入显示的值,如插入失败和找不到方法错误,我正在忍受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');
答案 0 :(得分:1)
最后我在facebook上找到了我朋友的解决方案
我们需要把
Testing = new Mongo.Collection('posts');
在lib文件夹中