2013-01-24 94 views
0

我試圖與Ember的pre4版本一起工作,但我在路由器上卡住了。Ember的路由器pre4

我收到一個錯誤,說Uncaught TypeError: Cannot Call method 'map' of undefined

Relavent代碼:

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" }); 
}); 

回答

1

我沒有看到什麼不好,你發佈的代碼。能夠在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。最小化版本針對生產使用進行了優化,因此不包含有用的調試消息,可以更容易地發現這些問題。

+0

謝謝!我缺少'handlebar.js',需要使用非縮小版本。謝謝你指出我。 – RyanJM