我刚升级到最新的ember.js。在那之后,我的应用程序开始失败。
这是Firebug输出:
DEBUG: -------------------------------
DEBUG: Ember : 1.0.0
DEBUG: Ember Data : 1.0.0-beta.2
DEBUG: Handlebars : 1.0.0
DEBUG: jQuery : 1.10.2
DEBUG: -------------------------------
Attempting URL transition to /
Transition #1: Beginning validation for transition to clocks.index
Transition #1: application: calling beforeModel hook
Transition #1: application: resolving model
Transition #1: application: calling afterModel hook
Transition #1: application: validation succeeded, proceeding
Transition #1: clocks: calling beforeModel hook
Transition #1: clocks: resolving model
Transition #1: clocks.index: transition was aborted
Transition #1: clocks: handling error: TypeError: App.Clock.find is not a function
Error while loading route:
TypeError: App.Clock.find is not a function
return App.Clock.find();
TypeError: App.Clock.find is not a function
return App.Clock.find();
TypeError: App.Clock.createRecord is not a function
以下是相关代码:
App.ClocksRoute = Ember.Route.extend({
model: function() {
var locationService = UtilitiesHelper.LocationService.getInstance();
locationService.getLocation(function(location) {
App.Clock.createRecord({
city: location.city,
country: location.country,
latitude: location.latitude,
longitude: location.longitude,
color: '#483D8B',
order: -10
});
});
return App.Clock.find();
}
});
我无法弄清楚新版本中的变化。
答案 0 :(得分:5)
在最新版本的Ember Data(Beta 2及更高版本)而不是App.Clock.find()
中,您必须执行this.get('store').find('clock')
。
请仔细阅读Ember Data Beta Transition documentation。第一部分介绍了find
。
您还需要将createRecord
更新为:
this.get('store').createRecord('clock', {
city: location.city,
country: location.country,
latitude: location.latitude,
longitude: location.longitude,
color: '#483D8B',
order: -10
});
虽然这些可能不是您将代码迁移到最新版本所需进行的唯一更改。这个post也可能会有所帮助。