如何根据 Meteor JS 中的按钮单击将模板数据附加到另一个模板?

How to append Template Data to another Template based on Button Click in Meteor JS?

一个模板有按钮,另一个模板包含一个文本 field.When 曾经单击过按钮,提交的文本同时附加到按钮模板,没有删除以前的文本字段,这意味着按钮被单击了 4 次4 个文本字段添加到按钮模板。

见以下代码:

HTML代码:

<head>
  <title>hello</title>
</head>

<body>
  <h1>Welcome to Meteor!</h1>

  {{> hello}}

</body>

<template name="hello">


    Add Text Fields here :

    <button>add another text box</button>

</template>

<template name="home">

    <input type="text" id="name" />

</template>

JS代码:

if (Meteor.isClient) {


  Template.hello.events({
    'click button': function () {

     //Here to write append logic
    }
  });
}

我对this.So一无所知请建议我为此做什么?

仅使用客户端集合。单击添加一个新记录。然后在主模板中你循环这个。 new Meteor.Collection(null) null 会告诉它它只是本地的,实际上不会在 MongoDB.

中创建集合
if (Meteor.isClient) {
    var buttonClicks = new Meteor.Collection(null),
            clickCounter = 0;

    Template.hello.events({
        'click button': function () {

            buttonClicks.insert({click: clickCounter++});
        }
    });

    Template.home.helpers({
        clicks: function () {
            return buttonClicks.find({});
        }
    });
}

<template name="home">
{{#each clicks}}
    <input type="text" id="name_{{click}}" />
{{/each}}
</template>