定义了两个完全相同的meteor本地集合和助手。一个助手工作。另一个没有';T

定义了两个完全相同的meteor本地集合和助手。一个助手工作。另一个没有';T,meteor,Meteor,我创建了这两个本地集合(代码实际上是一个接一个地编写的,如下所示): 在Template.myTemplate.rendered中我向这些集合中添加了一些初始信息(同样,代码是一个接一个): 我在helpers.js中找到了这两个全局帮助程序(一个接一个地定义) 加载页面时,我会立即在控制台中运行以下命令: > ShoppingCartCollection.findOne(); Object {sqft: "not yet entered", _id: "xcNmqJvMqqD5j7ww

我创建了这两个本地集合(代码实际上是一个接一个地编写的,如下所示):

Template.myTemplate.rendered中
我向这些集合中添加了一些初始信息(同样,代码是一个接一个):

我在
helpers.js
中找到了这两个全局帮助程序(一个接一个地定义)

加载页面时,我会立即在控制台中运行以下命令:

> ShoppingCartCollection.findOne();

Object {sqft: "not yet entered", _id: "xcNmqJvMqqD5j7wwn"}

> CurrentPricesCollection.findOne();

Object {hdrPhotos: 100, _id: "LP38E3MZgzuYjvSec"}
在我的模板中,我使用这些帮助程序,但是

{{currentPrice.hdrPhotos}} //displays nothing

{{shoppingCart.sqft}} //displays "not yet entered"

怎么。。。什么?这怎么可能?有什么我可能错过的陷阱吗?某种我不知道的依赖关系或加载顺序?

您发布的代码在这里运行良好

建议将此代码与您正在执行的操作的确切细节进行比较。还有,看 其他问题、打字错误等

以下是我使用的确切测试程序:

从零开始,在linux控制台上:

meteor创建sodebug

请注意,这将为“hello world”类型的程序生成文件

检查版本:

meteor --version
Release 0.8.1.1
编辑sodebug/sodebug.js:

if (Meteor.isClient) {
  // code autogenerated by meteor create
  Template.hello.greeting = function () {
    return "Welcome to sodebug.";
  };

  Template.hello.events({
    'click input': function () {
      // template data, if any, is available in 'this'
      if (typeof console !== 'undefined')
        console.log("You pressed the button");
    }
  });
  // add your code here
    ShoppingCartCollection = new Meteor.Collection(null);
    CurrentPricesCollection = new Meteor.Collection(null);

    ShoppingCartCollection.insert({"sqft" : "not yet entered"});
    CurrentPricesCollection.insert({"hdrPhotos" : 100}); 
    Handlebars.registerHelper("shoppingCart", function() {
    return ShoppingCartCollection.findOne();
    });

    Handlebars.registerHelper("currentPrice", function() {
    return CurrentPricesCollection.findOne();
    });
}

if (Meteor.isServer) {
  Meteor.startup(function () {
    // code to run on server at startup
  });
}
编辑sodebug.html:

<head>
  <title>sodebug</title>
</head>

<body>
  {{> hello}}
  {{> T1 }}
  {{> T2 }} 
</body>

<template name="T1">
<p>
{{shoppingCart.sqft}}
</p>
</template>
<template name="T2">
<p>
{{currentPrice.hdrPhotos}}
</p>
</template>
<template name="hello">
  <h1>Hello World!</h1>
  {{greeting}}
  <input type="button" value="Click" />
</template>

苏打水
{{>你好}
{{>T1}
{{>T2}

{{shoppingCart.sqft}

{{currentPrice.hdrPhotos}

你好,世界! {{问候语}
运行:
meteor运行

手动测试:

在本地主机上启动chromium浏览器:3000

检查web浏览器控制台中的数据集合。通过

检查web浏览器屏幕中的模板数据。通过


sodebug.html
文件中重新排序模板,检查web浏览器屏幕。通过

这两个助手呼叫是否也相邻?是的。肩并肩。相同的模板。在这里工作正常,将发布准确的文件。模板的顺序相反,未更改任何内容。Grrrr。。。我重新启动了meteor服务器。同样的事情。我会尝试重新设置。好的,我想我知道发生了什么client文件夹中的code>helpers.js与隐藏的
meteor
文件夹中的my
helpers.js
不同。但问题是,如果我删除隐藏文件夹中的
helpers.js
,然后执行
meteor rebuild all
,它将继续在隐藏文件夹中重建旧的、不同步的
helpers.js
.meteor
中的这个旧版本不包括我在OP.meteor 0.8.1.3中定义的全局帮助程序。但它怎么知道重建旧版本???重建旧版本的说明是从哪里来的?嗯。。。我关闭了我的文本编辑器(升华),以确保它没有锁定任何文件。我又做了一次重建,这次一切似乎都恢复了正常。但仍然没有解释Meteor是如何找到信息来重建旧版本的
helpers.js
meteor --version
Release 0.8.1.1
if (Meteor.isClient) {
  // code autogenerated by meteor create
  Template.hello.greeting = function () {
    return "Welcome to sodebug.";
  };

  Template.hello.events({
    'click input': function () {
      // template data, if any, is available in 'this'
      if (typeof console !== 'undefined')
        console.log("You pressed the button");
    }
  });
  // add your code here
    ShoppingCartCollection = new Meteor.Collection(null);
    CurrentPricesCollection = new Meteor.Collection(null);

    ShoppingCartCollection.insert({"sqft" : "not yet entered"});
    CurrentPricesCollection.insert({"hdrPhotos" : 100}); 
    Handlebars.registerHelper("shoppingCart", function() {
    return ShoppingCartCollection.findOne();
    });

    Handlebars.registerHelper("currentPrice", function() {
    return CurrentPricesCollection.findOne();
    });
}

if (Meteor.isServer) {
  Meteor.startup(function () {
    // code to run on server at startup
  });
}
<head>
  <title>sodebug</title>
</head>

<body>
  {{> hello}}
  {{> T1 }}
  {{> T2 }} 
</body>

<template name="T1">
<p>
{{shoppingCart.sqft}}
</p>
</template>
<template name="T2">
<p>
{{currentPrice.hdrPhotos}}
</p>
</template>
<template name="hello">
  <h1>Hello World!</h1>
  {{greeting}}
  <input type="button" value="Click" />
</template>