0
这是一个新的编程范例,所以如果你们可以指出我做错了什么,那将会有所帮助。流星:来自输入字段的值不会存储到集合
情景:用户写入两个输入字段并点击输入。系统将数据插入到Mongo Db集合中。
收集如下
{ "_id" : ObjectId("55a289685331cc2c9a97c2e6"), "text" : "Hello jack.", "createdAt" : ISODate("2015-07-12T15:36:08.558Z"), "info"
: “[email protected]”}
HTML
<!-- add a form below the h1 -->
<form class="new-task">
<input type="text" name="data" placeholder="Type on, little one" />
<input type="text" name = "info" placeholder="info"/>
</form>
</header>
<br/>
<h1>This is what you wrote</h1>
{{#each tasks}}
{{>task}}
{{/each}}
</body>
<template name="task">
<li>{{text}}, {{info}}</li>
</template>
,做插入
Tasks = new Mongo.Collection("tasks");
if (Meteor.isClient) {
// This code only runs on the client
Template.body.helpers({
tasks: function() {
return Tasks.find({});
}
});
// submit form
Template.body.events({
"submit .new-task":function(event){
var text = event.target.data.value;
var info = event.target.info.value;
Tasks.insert({
text: text,
createdAt: new Date(),
info: info
});
return false;
}
});
}
没有工作兄弟。 thnks,你:) –
只需尝试一次'task.insert console.log(“Info:%s”,info);'并检查var是否具有正确的值。另外,尝试在Task.insert内一次'info:“Sample Text”'作为一个固定值。 –
我调试了源代码,发现表单没有在“Enter”上提交。 我包含在一个提交按钮中,它工作。谢谢汤姆,我会接受你的回答,因为你帮助了我,当你不需要你时,你将我引向正确的道路。 –