1

この非常にシンプルなアプリは機能していません。リストが表示されません。なんで?Meteorがどのように機能するかについて重要な何かを見逃しているに違いありません。

レシピ.html

<body>
    <h3>Recipes</h3>
    {{> recipes}}
</body>

<template name="recipes">
    <ul>
        {{#each recipes}}
            <li>{{name}}</li>
        {{/each}}
    </ul>
</template>

レシピ.コーヒー

Recipes = new Meteor.Collection("recipes")

if Meteor.is_client
    Meteor.startup ->
        Meteor.autosubscribe(->
            Meteor.subscribe('recipes')
        )

        # THIS IS NOT WORKING
        Template.recipes.recipes ->
            return Recipes.find()

if Meteor.is_server
    Meteor.startup ->
        if Recipes.find().count() == 0
            data = [
               name: "Chocolate Chip Cookies"
            ,
               name: "Spring Rolls"
           ]

        for item in data
            Recipes.insert(item)

    Meteor.publish('recipes', ->
        return Recipes.find()
    )

エラー

Uncaught TypeError: Object function (data) {
      var getHtml = function() {
        return raw_func(data, {
          helpers: partial,
          partials: Meteor._partials
        });
      };

      var react_data = { events: (name ? Template[name].events : {}),
                         event_data: data,
                         template_name: name };

      return Meteor.ui.chunk(getHtml, react_data);
    } has no method 'recipes' 

自動公開ありとなしでこれを試しました。ここで何がわからないのですか?

編集:

Jasdが指摘したように、私は以前に間違ったコードを投稿しました。現在のコードは問題のコードです。

4

3 に答える 3

1

すべきではありません:

Template.recipes.recipes = ->
    return Recipes.find()

1.)関数をに割り当て、2。)テンプレートのTemplate.recipes.recipesリストを反復処理するためです。私が推測するキーで別のオブジェクトを返す必要はありません。recipesrecipesrecipes

于 2012-08-10T17:00:08.920 に答える
0

これである必要があります-

Recipes = new Meteor.Collection("recipes")

if Meteor.is_client
    Meteor.startup ->
        Meteor.autosubscribe(->
            Meteor.subscribe('recipes')
        )

    # OUTINDENT
    # ASSIGNMEMT, NOT FUNCTION CALL
    Template.recipes.recipes = ->
        return Recipes.find()

if Meteor.is_server
    Meteor.startup ->
        if Recipes.find().count() == 0
            data = [
               name: "Chocolate Chip Cookies"
            ,
               name: "Spring Rolls"
            ]

            # INDENT
            for item in data
                Recipes.insert(item)

    Meteor.publish('recipes', ->
        return Recipes.find()
    )
于 2012-08-11T05:22:46.490 に答える
0
  1. に割り当てることを確認する必要がありTemplate.recipe.recipesます(qnのタイプミスの可能性があります)

    Template.recipes.recipes = ->
      return Recipes.find()
    
  2. Meteor.startupテンプレートが評価された後に実行される(したがって、そうなると思わTemplate.recipe.recipesれる)で、これを実行する必要はありません。ブロックnullの最上位に移動すると、is_client問題ないと思います。

于 2012-08-11T05:22:59.483 に答える