0

我有一个 html 按钮。我想在单击时插入一个集合。我该怎么做呢?我知道如何从控制台执行此操作,但不知道页面。我目前正在使用基本的 hello world 示例。

下面是我的代码

var savedState = new Meteor.Collection("SavedState");

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

    savedState.insert({Category:"SYNTHS", items: [{Name:"whatever"}]});

    }
  });
}
4

1 回答 1

0

你遇到了什么错误?假设您围绕它编写的代码是正确的,那么您编写的代码是有效的。见下文。

Javascript:

var savedState = new Meteor.Collection("SavedState");

if (Meteor.isClient) {
    Template.hello.events({
        'click input' : function () {
            savedState.insert({Category:"SYNTHS", items: [{Name:"whatever"}]});
        }
    });
}

模板:

<body>
    {{> hello}}
</body>

<template name="hello">
    <input type="button" value="Click" />
</template>
于 2013-02-27T22:46:31.197 回答