试图学习流星。我浏览了Discover Meteor书,现在我正在尝试自己创建一个简单的应用程序,但我只是设置了一些基本的模板和路由。我没有显示对象的值,而是获得了[object Object]。我在另一个问题中读到,这是尝试打印对象而不是字符串的结果,但我认为使用{{temperature}}和{{outlook}}会返回值....
感觉我错过了一些基本的东西。代码如下:
的layout.html:
<template name="layout">
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Project name</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div id="main" class="row-fluid">
{{yield}}
</div>
</template>
router.js:
Router.configure({
layoutTemplate: 'layout'
});
Router.map(function() {
this.route('forecastList', {path: '/'});
});
forecast_list.html:
<template name="forecastList">
<div class="forecast-container">
<div class="row forecasts">
{{#each forecasts}}
{{> forecastItem}}
{{/each}}
</div>
</div>
</template>
forecast_list.js:
var forecastData = [
{
temperature: '30',
outlook: 'Today is forecasted to be sunny.'
},
{
temperature: '75',
outlook: 'Today is forecasted to be cloudy.'
}
];
Template.forecastList.helpers({
forecast: forecastData
});
forecast_item.html:
<template name="forecastItem">
<div class="forecast">
<div class="forecast-content">
<h1>{{temperature}}</h1>
<h2>{{outlook}}</h2>
</div>
</div>
</template>
答案 0 :(得分:0)
Template.forecastList.helpers({
forecasts: function(){
return forecastData;
}
});