Question

I'm trying to work with Ember's pre4 release, but I'm getting stuck on the Router.

I get an error that says Uncaught TypeError: Cannot Call method 'map' of undefined.

Relavent code:

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

Relative documentation.

I've loaded Ember.js and jQuery. Ember pre4 also throws an error: Uncaught TypeError: Object prototype may only be an Object or null.

Am I doing something wrong? Are the guides just not updated?


The code I have so far:

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" });
});
Était-ce utile?

La solution

I'm not seeing anything wrong with the code you posted. Was able to run it in jsbin, and after adding "site" as the default route the app appears to be working.

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>

See jsbin for working copy.

My best guess is that your errors are coming from some either an incompatible version of jQuery or because you don't have handlebars.js - both are required to run ember. Also, in development be sure to use ember-1.0.0-pre.4.js! instead of ember-1.0.0-pre.4.min.js. The minimized version is optimized for production use so does not include helpful debug messages that will make it easier to spot these kind of problems.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top