使用meteor将数据库的更新值附加到textarea

使用meteor将数据库的更新值附加到textarea,meteor,Meteor,我是meteor的新手,通过示例学习创建web应用程序。我想将数据库的更新值附加到html文本区域。 例如,如果我更新键“sensor”的值,则需要将传感器值附加到textarea。我如何使用meteor做到这一点?您使用车把辅助工具并将更改绑定到文本区域以更新字段:例如 html 最后,您的服务器端js也需要一些东西: //The same collection as on your client MyCollection = new Meteor.Collection("mycollecti

我是meteor的新手,通过示例学习创建web应用程序。我想将数据库的更新值附加到html文本区域。
例如,如果我更新键“sensor”的值,则需要将传感器值附加到textarea。我如何使用meteor做到这一点?

您使用车把辅助工具并将更改绑定到文本区域以更新字段:例如

html

最后,您的服务器端js也需要一些东西:

//The same collection as on your client
MyCollection = new Meteor.Collection("mycollection");

//Insert an address on the first time if there is nothing in yet:
Meteor.startup(function() {
    if(!MyCollection.findOne({name:address})) {
        MyCollection.insert({name:address,value:"10 Downing St, London, United Kingdom"});
    }
});
这是它的基本要点,当文本区域发生更改时更新它,并在模板中显示一个值。当其更新时,也会将更新反映到所有选项卡/查看页面的每个人

//Your collection that stores your data
MyCollection = new Meteor.Collection("mycollection");

//Your handlebars helper to give some data to address
Template.hello.address = function() {
    var address = MyCollection.findOne({name:address});
    if(address) return address.value;
}

//Something to bind changes to your address to your collection
Template.hello.events({
    'change [name=address]' : function(e,cxt) {
        var address = MyCollection.findOne({name:address});
        MyCollection.update(address._id, {$set:{value:e.currentTarget.value}});
    }
});
//The same collection as on your client
MyCollection = new Meteor.Collection("mycollection");

//Insert an address on the first time if there is nothing in yet:
Meteor.startup(function() {
    if(!MyCollection.findOne({name:address})) {
        MyCollection.insert({name:address,value:"10 Downing St, London, United Kingdom"});
    }
});