【发布时间】:2014-11-05 03:37:21
【问题描述】:
在我的 Ember CLI 应用程序中,我有一个名为 insights 的路由。该路由扩展了 check-user mixin。
/routes/insights.js:
import Ember from 'ember';
import CheckUser from 'client-web/mixins/check-user';
export default Ember.Route.extend(CheckUser, {
setupController: function(controller, model) {
var _this = this;
if (this.get('userAuthenticated') === true) {
// Do some stuff here
} else {
_this.transitionToRoute('sign-in');
}
},
getToday: function() {
var today = new Date(),
dd = today.getDate(),
mm = today.getMonth() + 1,
yyyy = today.getFullYear();
if (dd < 10) dd = '0' + dd;
if (mm < 10) mm = '0' + mm;
today = mm + '/' + dd + '/' + yyyy;
return today;
},
getTomorrow: function() {
var toDate = new Date(this.getToday());
toDate.setDate(toDate.getDate() + 1);
var day = toDate.getDate(),
month = toDate.getMonth() + 1,
year = toDate.getFullYear();
if (day < 10) day = '0' + day;
if (month < 10) month = '0' + month;
var tomorrow = month + '/' + day + '/' + year;
return tomorrow;
}
});
当我使用 this.transitionTo('insights') 从另一个路由转换到该路由或手动将页面刷新到 myapplication.com/insights 时,一切正常,此路由呈现我指定的模板。但是,我的模板中有一些链接使用 {{link-to}} 帮助程序链接到见解路线。当用户单击其中一个链接时,我收到以下错误:
Error while processing route: insights undefined is not a function TypeError: undefined is not a function
at __exports__.default.Ember.Route.extend.setupController (client-web/routes/insights.js:15:14)
at apply (http://localhost:3000/assets/vendor.js:21144:27)
at superWrapper [as setupController] (http://localhost:3000/assets/vendor.js:20721:15)
at EmberObject.extend.setup (http://localhost:3000/assets/vendor.js:51254:18)
at handlerEnteredOrUpdated (http://localhost:3000/assets/vendor.js:54266:36)
at http://localhost:3000/assets/vendor.js:54235:18
at forEach (http://localhost:3000/assets/vendor.js:55303:54)
at setupContexts (http://localhost:3000/assets/vendor.js:54234:9)
at finalizeTransition (http://localhost:3000/assets/vendor.js:54404:9)
at http://localhost:3000/assets/vendor.js:53954:20
第 15 行是 getToday 函数。不知道为什么只有当我使用链接到帮助程序时它才会在那里中断。我错过了什么?
【问题讨论】:
标签: javascript ember.js ember-cli