2013-04-29 53 views

回答

0

您使用車把助手和綁定更改您的文本區域更新域:如

HTML

<template name="hello"> 
    <textarea name="address">{{address}}</textarea> 
</template 

客戶端JS

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

最後你需要在你的服務器端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"}); 
    } 
}); 

這就是它更新文本區域時的基本要點,並在模板中顯示值。當它更新時,它也將反映所有查看頁面的標籤/每個人的更新。