2015-06-23 164 views
0

我刚开始创建一个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 
     }; 
    } 
    } 
}); 

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

回答

1

你需要把客户端代码无论是在/client文件夹或裹在一张支票Meteor.isClient

if (Meteor.isClient) { 

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

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

} 

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

你可以在http://docs.meteor.com/#/full/structuringyourapp

找到更多关于结构化流星应用的信息