2012-04-29 14 views
1

好吧,我不確定爲什麼我不能渲染代碼。首先,如果我CONSOLE.LOG users.content我得到我想要的內容,但我一些如何不能將它傳遞給一個文本,使其顯示的它...meteor and textareas

Users = new Meteor.Collection("users"); 

if(Meteor.is_client){ 
    Template.inputUser.code = function(){ 
    var el = Users.find({name:"oscar"}); 
    el.forEach(function(users){ 
     console.log(users.content); 
    }) 
    } 
} 

,然後在我的HTML模板我有

<body>{{> inputUser}}</body> 

<template name="inputUser"> 
<textarea>{{content}}</textarea> 
</template> 

而且我會對數據庫記錄吸既然這麼

if(Meteor.is_server) 
    Users.insert({name:"oscar",content:"hello world"}) 

感謝您的幫助球員。

回答

0

首先你的方法Template.inputUser.code應該返回的東西,你也應該注意,它不會使用該模板被稱爲無論是作爲它需要一個{{code}}呼叫它,而不是{{content}}

第二點是數據庫內容不如果您已禁用autopublish包,則始終可用(如果是這樣),請使用publish(在服務器代碼中)和subscribe(在客戶端代碼中)檢出:http://docs.meteor.com/#meteor_subscribe您可以使用它來檢查客戶端何時顯示所有數據。例如:

Meteor.subscribe('allusers', function() { 
    Template.inputUser.code = function(){ 
    var user = Users.findOne({name:"oscar"}); 
    return user.content; 
    } 
}); 

... 

Meteor.publish('allusers', function() { 
    return Users.find(); 
});