加载路由时出错,无法读取undefined的属性

时间:2013-12-03 10:58:14

标签: javascript ember.js ember-data single-page-application

我正在尝试加载/bookmarks页面。

当我点击{{#link-to 'bookmarks'}}Bookmarks{{/link-to}}时,我收到错误消息:

Assertion failed: Error while loading route: TypeError: Cannot read property 'url' of undefined

我有一个书签模型:

App.Bookmark = DS.Model.extend({
    title: DS.attr('string'),
    url: DS.attr('string')
});

书签路线:

App.BookmarksRoute = Ember.Route.extend({
    model: function(){
      return this.store.find('bookmark');
    }
});

路由器;

App.Router.map(function(){
    this.resource('bookmarks', function(){
        this.route('new');
    });
});

书签控制器:

App.BookmarksController = Ember.ArrayController.extend();

书签模板:

<script type="text/x-handlebars" data-template-name="bookmarks">
    <h2>All my bookmarks</h2>

    <table>
      <thead>
        <tr>
          <th>Title</th>
          <th>URL</th>
        </tr>
      </thead>
      <tbody>
        {{#each controller}}
          <tr>
            <td>{{title}}</td>
            <td>{{url}}</td>
          </tr>

        {{/each}}
      </tbody>
    </table>

    {{#linkTo 'bookmarks.new'}}New bookmark{{/linkTo}}

    {{outlet}}
  </script>

1 个答案:

答案 0 :(得分:1)

声明您的适配器如下:

App.ApplicationAdapter = DS.LSAdapter;