1

コードをレンダリングできない理由がわかりません。最初に、console.log users.content を実行すると、必要なコンテンツを取得できますが、それをテキストエリアに渡してそれを表示することができません...

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

2 番目のポイントは、自動公開パッケージを無効にしている場合、データベースのコンテンツが常に利用できるとは限らないことです。その場合は、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();
});
于 2012-04-30T01:29:27.893 に答える