简体   繁体   English

流星:输入字段中的值不存储到集合中

[英]meteor: value from input fields is not stored to collection

This is a new programming paradigm for me, so if you guys can point out what i'm doing wrong, that would be helpful. 这对我来说是一个新的编程范例,因此如果你们能指出我做错了什么,那将会很有帮助。

Scenario: The user writes into two input fields and hits enter. 场景:用户写入两个输入字段,然后按Enter。 The system inserts data into Mongo Db collection. 系统将数据插入Mongo Db集合。

collection is as follows 收藏如下

{ "_id" : ObjectId("55a289685331cc2c9a97c2e6"), "text" : "Hello jack.", "createdAt" : ISODate("2015-07-12T15:36:08.558Z"), "info"

: "lee@not.com" } :“ lee@not.com”}

html 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>

The Js file that does the insert 执行插入的Js文件

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

}

What is your question? 你的问题是什么?

I guess: Why is the info field not filled in my collection? 我猜:为什么我的收藏夹中没有填写信息字段?

As I see, I would remove the blanks in your template, try: 如我所见,我将删除模板中的空白,请尝试:

name="info"

Cheers Tom 干杯汤姆


UPDATE: As you can see in the comments dialog, leo.warrior has found the real answer himself and added a submit button. 更新:正如您在评论对话框中看到的那样,leo.warrior亲自找到了真正的答案,并添加了一个提交按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM