找到你要的答案

Q:Template not defined - Meteor

Q:模板未定义- Meteor

I just started creating a Meteor app and added the dburles:google-maps package, I seem to have been following the steps he indicates in the tutorial of how to implement it, but I get the error Template not defined, my code is as follows:

.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
      };
    }
  }
});

Any ideas, I checked the finished repo and the code seems to be 1:1 with mine...?

我刚开始创建一个应用程序,增加了dburles流星:谷歌地图包,我似乎已经按照下列步骤,他表示在如何实现它的教程,但我没有定义错误的模板,我的代码如下:

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

任何想法,我检查完成的回购和代码似乎是1:1我…?

answer1: 回答1:

You need to put the client code either in a /client folder or wrapped in a check for Meteor.isClient:

if (Meteor.isClient) { 

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

    Template.map.helpers({ ... });

}

If not, Meteor will run your code on the client and server, and Template is not defined on the server.

You can find more information about structuring your Meteor app at http://docs.meteor.com/#/full/structuringyourapp

你需要把客户端代码在客户端文件夹或包裹在检查Meteor.isClient:

if (Meteor.isClient) { 

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

    Template.map.helpers({ ... });

}

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

你可以找到关于构建你的流星应用在HTTP的更多信息:/ /文档。流星。COM / # /全/ structuringyourapp

javascript  meteor