【问题标题】:Ember's Router for pre4用于 pre4 的 Ember 路由器
【发布时间】:2013-01-24 02:08:43
【问题描述】:

我正在尝试使用 Ember 的 pre4 版本,但在路由器上卡住了。

我收到一条错误消息,上面写着Uncaught TypeError: Cannot Call method 'map' of undefined。

相关代码:

App.Router.map(function() {
  this.route("about", { path: "/about" });
  this.route("favorites", { path: "/favs" });
});

相对documentation。

我已经加载了 Ember.js 和 jQuery。 Ember pre4 也会抛出错误:Uncaught TypeError: Object prototype may only be an Object or null。

我做错了吗?指南没有更新吗?


我目前的代码:

window.App = Ember.Application.create({
  ApplicationView: Ember.View.extend({
    templateName: 'application'
  }),
  ApplicationController: Ember.Controller.extend({
  }),

  SiteView: Em.View.extend({
    templateName: 'site-template'
  }),
  SiteController: Em.ArrayController.extend(),

});

App.Router.map(function() {
  this.route("about", { path: "/about" });
  this.route("favorites", { path: "/favs" });
});

【问题讨论】:

    标签: ember.js ember-router


    【解决方案1】:

    我没有发现您发布的代码有任何问题。能够在 jsbin 中运行它,并且在添加“站点”作为默认路由后,该应用程序似乎正在运行。

    App = Ember.Application.create({
      ApplicationView: Ember.View.extend({
        templateName: 'application'
      }),
      ApplicationController: Ember.Controller.extend({
      }),
    
      SiteView: Em.View.extend({
        templateName: 'site-template'
      }),
      SiteController: Em.ArrayController.extend()
    
    });
    
    App.Router.map(function() {
      this.route("site", { path: "/" });
      this.route("about", { path: "/about" });
      this.route("favorites", { path: "/favs" });
    });
    
    <script type="text/x-handlebars" data-template-name="site-template">
      This is the site template
    </script>
    
    <script type="text/x-handlebars">
      This is the application template
      {{outlet}}
    </script>
    

    有关工作副本,请参阅 jsbin。

    我最好的猜测是,您的错误来自不兼容的 jQuery 版本,或者因为您没有 handlebars.js - 两者都是运行 ember 所必需的。另外,在开发中一定要使用ember-1.0.0-pre.4.js!而不是 ember-1.0.0-pre.4.min.js。最小化版本针对生产使用进行了优化,因此不包含有助于更容易发现此类问题的有用调试消息。

    【讨论】:

    • 谢谢!我错过了handlebar.js,需要使用非缩小版本。感谢您向我指出这一点。
    猜你喜欢
    • 2013-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多