[英]In Ember pre4's router, how do you trigger a route event from within another route?
[英]Ember's Router for pre4
我正在嘗試使用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中運行它,並且在添加“ site”作為默認路由后,該應用似乎正在運行。
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。 最小化版本針對生產用途進行了優化,因此不包含有用的調試消息,這些消息將使發現此類問題更加容易。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.