1

好的,所以我不确定为什么我不能渲染代码。首先,如果我 console.log users.content 我得到了我想要的内容,但我有些无法将它传递给 textarea 以便它显示它......

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"})

谢谢你们的帮助。

4

1 回答 1

0

首先你的方法Template.inputUser.code应该返回一些东西,你还应该注意它不会被那个模板调用,因为它需要{{code}}调用它而不是{{content}}

第二点是如果您禁用了自动发布包,数据库内容并不总是可用,如果是这样,请使用发布(在服务器代码中)和订阅(在客户端代码中)检查: 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();
});
于 2012-04-30T01:29:27.893 回答