Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么可以';我不能用Meteor渲染这个简单的列表吗?_Javascript_Coffeescript_Meteor - Fatal编程技术网

Javascript 为什么可以';我不能用Meteor渲染这个简单的列表吗?

Javascript 为什么可以';我不能用Meteor渲染这个简单的列表吗?,javascript,coffeescript,meteor,Javascript,Coffeescript,Meteor,这个非常简单的应用程序不起作用。我的名单没有出现。为什么?我一定错过了一些关于流星如何工作的重要信息 recipes.html 食谱 {{>食谱} {{{#每个食谱} {{name}} {{/每个}} 食谱。咖啡 Recipes=新流星系列(“Recipes”) 如果流星是你的客户 Meteor.startup-> Meteor.自动订阅(-> Meteor.subscribe(“食谱”) ) #这不起作用 Template.recipes.recipes-> 返回配方。查找() 如果M

这个非常简单的应用程序不起作用。我的名单没有出现。为什么?我一定错过了一些关于流星如何工作的重要信息

recipes.html


食谱
{{>食谱}
    {{{#每个食谱}
  • {{name}}
  • {{/每个}}
食谱。咖啡

Recipes=新流星系列(“Recipes”)
如果流星是你的客户
Meteor.startup->
Meteor.自动订阅(->
Meteor.subscribe(“食谱”)
)
#这不起作用
Template.recipes.recipes->
返回配方。查找()
如果Meteor.is_服务器
Meteor.startup->
如果Recipes.find().count()=0
数据=[
名称:“巧克力曲奇”
,
名称:“春卷”
]
对于数据中的项
配方。插入(项目)
Meteor.publish('recipes',->
返回配方。查找()
)
错误

未捕获类型错误:对象函数(数据){
var getHtml=function(){
返回原始函数(数据{
助手:部分,
部分:流星
});
};
var react_data={events:(名称?模板[name]。事件:{}),
事件数据:数据,
模板名称:name};
返回Meteor.ui.chunk(getHtml,react\u数据);
}没有“配方”方法
我尝试过使用自动发布和不使用自动发布。我在这里不明白什么

编辑:

正如Jasd指出的那样,我之前发布了错误的代码。现在的代码就是有问题的代码。

不应该是:

Template.recipes.recipes = ->
    return Recipes.find()
因为1.)将函数分配给
Template.recipes.recipes
,2.)迭代模板
recipes
的列表
recipes
。我想您不需要返回另一个带有键
recipes
的对象。

是否应该:

Template.recipes.recipes = ->
    return Recipes.find()
因为1.)将函数分配给
Template.recipes.recipes
,2.)迭代模板
recipes
的列表
recipes
。我想您不需要返回另一个带有键
recipes
的对象。

应该是这样的-

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()
    )
应该是这个吗-

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()
    )
  • 您需要确保分配给
    Template.recipe.recipes
    (可能是qn中的输入错误)

  • 你不想在
    Meteor.startup
    中这样做,它是在模板被评估后运行的(因此它会认为
    template.recipe.recipes
    null
    )--将它移动到
    is\u客户机
    块的顶层,我认为这样就可以了

  • 您需要确保分配给
    Template.recipe.recipes
    (可能是qn中的输入错误)

  • 你不想在
    Meteor.startup
    中这样做,它是在模板被评估后运行的(因此它会认为
    template.recipe.recipes
    null
    )--将它移动到
    is\u客户机
    块的顶层,我认为这样就可以了


  • 你说得对,但那只是我在发布代码时犯的一个错误。我已经编辑了这个问题,现在只显示有问题的代码。那么
    =
    呢?我想你需要它。你是对的,但那只是我在发布代码时犯的一个错误。我已经编辑了这个问题,现在只显示有问题的代码。那么
    =
    呢?我想你需要它。这是第1条的意思。)