【问题标题】:Template not defined - Meteor模板未定义 - Meteor
【发布时间】:2015-06-24 04:00:34
【问题描述】:

我刚刚开始创建一个 Meteor 应用程序并添加了 dburles:google-maps 包,我似乎一直按照他在如何实现它的教程中指示的步骤进行操作,但我收到错误 Template not defined,我的代码如下如下:

.html

<head>
  <meta charset="utf-8">
  <title>project-j</title>
  <meta name="description" content="Let's see where it takes us">
  <meta name="viewport" content="user-scalable=no, initial-scale=1, minimal-ui, maximum-scale=1, minimum-scale=1" />
</head>

<body>
  {{> map}}
</body>


<template name="map">
  <div class="map-container">
    {{> googleMap name="map" options=mapOptions}}
  </div>
</template>

.js

Meteor.startup(function() {
  GoogleMaps.load();
});

Template.map.helpers({
  mapOptions: function() {
    if (GoogleMaps.loaded()) {
      return {
        center: new google.maps.LatLng(-37.8136, 144.9631),
        zoom: 8
      };
    }
  }
});

任何想法,我检查了完成的 repo,代码似乎与我的代码是 1:1...?

【问题讨论】:

    标签: javascript meteor


    【解决方案1】:

    您需要将客户端代码放在/client 文件夹中或包装在Meteor.isClient 的检查中:

    if (Meteor.isClient) { 
    
        Meteor.startup(function() {...});
    
        Template.map.helpers({ ... });
    
    }
    

    如果没有,Meteor 将在客户端服务器上运行您的代码,并且在服务器上没有定义模板。

    您可以在http://docs.meteor.com/#/full/structuringyourapp找到更多关于构建 Meteor 应用程序的信息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-20
      • 2012-05-13
      • 1970-01-01
      • 2015-05-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多