Meteor 应用程序正在打印 [object Object] 而不是值?
Meteor app is printing [object Object] instead of values?
正在尝试学习 Meteor。我浏览了 Discover Meteor 一书,现在正尝试自己创建一个简单的应用程序,但我只是设置了一些基本模板和路由。我没有显示对象的值,而是获取 [object Object]。我在另一个问题中读到,这是尝试打印对象而不是字符串的结果,但我认为使用 {{temperature}} 和 {{outlook}} 会 return 值....
感觉好像缺少一些基本的东西。代码如下:
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>
Template.forecastList.helpers({
forecasts: function(){
return forecastData;
}
});
正在尝试学习 Meteor。我浏览了 Discover Meteor 一书,现在正尝试自己创建一个简单的应用程序,但我只是设置了一些基本模板和路由。我没有显示对象的值,而是获取 [object Object]。我在另一个问题中读到,这是尝试打印对象而不是字符串的结果,但我认为使用 {{temperature}} 和 {{outlook}} 会 return 值....
感觉好像缺少一些基本的东西。代码如下:
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>
Template.forecastList.helpers({
forecasts: function(){
return forecastData;
}
});