Javascript 余烬-对象没有方法';地图';

Javascript 余烬-对象没有方法';地图';,javascript,ember.js,ember-data,Javascript,Ember.js,Ember Data,我正在阅读ember.js指南来学习ember,我正在使用最新版本的和handlebar.js。我能够成功地建立一个基本导航,在视图之间切换。但是,在尝试将模型与{{{each model}}集成时,我收到一条错误消息:Uncaught TypeError:Object#没有方法“map” 很多人似乎都提出了一个相关的问题,但解决办法总是更新我已经做过的ember版本 我相信我已经完全遵循了教程,我的代码如下 App = Ember.Application.create(); App.Stor

我正在阅读ember.js指南来学习ember,我正在使用最新版本的和handlebar.js。我能够成功地建立一个基本导航,在视图之间切换。但是,在尝试将模型与
{{{each model}}
集成时,我收到一条错误消息:Uncaught TypeError:Object#没有方法“map”

很多人似乎都提出了一个相关的问题,但解决办法总是更新我已经做过的ember版本

我相信我已经完全遵循了教程,我的代码如下

App = Ember.Application.create();

App.Store = DS.Store.extend({
    revision: 12,
    // Says we are specifying all models in js
    adapter: 'DS.FixtureAdapter'
});

App.Router.map(function() {
    this.resource('posts');
    this.resource('about');
});

App.PostsRoute = Ember.Route.extend({
    model: function() {
        return App.Post.find();
    }
});

App.Post = DS.Model.extend({
    title: DS.attr('string'),
    author: DS.attr('string'),
    intro: DS.attr('string'),
    extended: DS.attr('string'),
    publishedAt: DS.attr('date')
});

App.Post.FIXTURES = ({
    id: 1,
    title: 'Book Title',
    author: 'Dave',
    publishedAt: new Date('12-27-2012'),
    intro: 'This is an introduction to the book',
    extended: 'This is an even longer introduction to the book'
}, {
    id: 2,
    title: 'Book Title 2',
    author: 'James',
    publishedAt: new Date('08-13-2012'),
    intro: 'This is an introduction to another book',
    extended: 'This is an even longer introduction to another book'
});
以及有关的标记:

<script type="text/x-handlebars">
<div class="navbar">
    <div class="navbar-inner">
        {{#linkTo 'index' classNames='brand'}}Brand{{/linkTo}}
        <ul class="nav">
            <li>{{#linkTo 'about'}}About{{/linkTo}}</li>
            <li>{{#linkTo 'posts'}}Posts{{/linkTo}}</li>
        </ul>
    </div>
</div>
{{outlet}}
</script>

<script type="text/x-handlebars" id="about">
<div class="about">
<p>Here is some text about the page</p>
</div>
</script>

<script type="text/x-handlebars" id="posts">
<div class="container-fluid">
    <div class="row-fluid">
        <div class="span3">
            <table class='table'>
            <thead>
                <tr><th>Recent Posts</th></tr>
            </thead>
            {{#each model}}
            <tr>
                <td><a href="#">{{title}} <small class='muted'>by {{author}}</small></a></td>
            </tr>
            {{/each}}
            </table>
        </div>
        <div class="span9">
        </div>
    </div>
</div>
</script>

{{{链接到'index'classNames='brand'}}品牌{{/linkTo}
  • {{{linkTo'about'}}关于{{/linkTo}
  • {{{链接到'帖子'}帖子{{/linkTo}
{{outlet}} 这里有一些关于这个页面的文字

最近的职位 {{{#每个模型} {{/每个}}

非常感谢所有的帮助,如果这个问题的格式很糟糕,我很抱歉——这是我的第一个问题!干杯

尝试使用控制器而不是模型来迭代阵列控制器中的模型

        {{#each controller}}
           <tr>
               <td><a href="#">{{title}} <small class='muted'>by {{author}}</small></a></td>
           </tr>
        {{/each}}
{{#每个控制器}
{{/每个}}

这里的主要问题是您的
{{{each}}
语句的格式有点不正确,您应该像这样迭代
控制器
对象:

{{#each controller}}
  <tr>
    <td><a href="#">{{title}} <small class='muted'>by {{author}}</small></a></td>
  </tr>
{{/each}}
{{#每个控制器}
{{/每个}}

这是因为Ember控制器充当其对象的代理,或者在
Ember.ArrayController的情况下充当其数组的代理

太好了,谢谢。在将您的建议与在网站上找到的代码布局相结合后,我能够得到一个可用的应用程序。谢谢(如果可以,我会投票,对不起)没问题,很高兴我能帮上忙。