0

正在尝试学习 Meteor。我浏览了 Discover Meteor 这本书,现在我正在尝试自己创建一个简单的应用程序,但我只是设置了一些基本的模板和路由。我没有显示对象的值,而是得到 [object Object]。我在另一个问题中读到这是尝试打印对象而不是字符串的结果,但我认为使用 {{temperature}} 和 {{outlook}} 会返回值......

感觉我缺少一些基本的东西。代码如下:

布局.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>

路由器.js:

    Router.configure({
    layoutTemplate: 'layout'
});

Router.map(function() {
    this.route('forecastList', {path: '/'});
});

预测列表.html:

<template name="forecastList">
<div class="forecast-container">
    <div class="row forecasts">
        {{#each forecasts}}
            {{> forecastItem}}
        {{/each}}
    </div>
</div>
</template>

预测列表.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
});

预测项目.html:

<template name="forecastItem">
    <div class="forecast">
        <div class="forecast-content">
            <h1>{{temperature}}</h1>
            <h2>{{outlook}}</h2>
        </div>
    </div>
</template>
4

1 回答 1

0
Template.forecastList.helpers({
    forecasts: function(){
       return forecastData;
    }
});
于 2015-01-29T23:04:18.890 回答