适用于pre4的Ember's Router



我正在尝试使用Ember的pre4版本,但我被困在路由器上。

我收到一个错误,说Uncaught TypeError: Cannot Call method 'map' of undefined.

相关代码:

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

相关文档。

我已经加载了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" });
});

我没有看到您发布的代码有任何问题。能够在 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版本,或者因为你没有车把.js - 两者都是运行余烬所必需的。另外,在开发中一定要使用 ember-1.0.0-pre.4.js!而不是 ember-1.0.0-pre.4.min.js。最小化版本针对生产使用进行了优化,因此不包含有用的调试消息,这些消息将更容易发现此类问题。

最新更新