在post之后,在我与Yeoman和Ember创建工作流程时,我点击了 /#/ story / new url我收到此错误:
Error while loading route: Getbookmarks.StoryEditRoute<.model@http://localhost:9000/scripts/combined-scripts.js:117
superWrapper@http://localhost:9000/bower_components/ember/ember.js:1230
getModel@http://localhost:9000/bower_components/ember/ember.js:33281
model@http://localhost:9000/bower_components/ember/ember.js:33209
invokeCallback@http://localhost:9000/bower_components/ember/ember.js:9427
publish@http://localhost:9000/bower_components/ember/ember.js:9097
publishFulfillment@http://localhost:9000/bower_components/ember/ember.js:9517
DeferredActionQueues.prototype.flush@http://localhost:9000/bower_components/ember/ember.js:5650
Backburner.prototype.end@http://localhost:9000/bower_components/ember/ember.js:5741
Backburner.prototype.run@http://localhost:9000/bower_components/ember/ember.js:5780
Ember.run@http://localhost:9000/bower_components/ember/ember.js:6181
runInitialize@http://localhost:9000/bower_components/ember/ember.js:38453
jQuery.Callbacks/fire@http://localhost:9000/bower_components/jquery/jquery.js:2913
jQuery.Callbacks/self.fireWith@http://localhost:9000/bower_components/jquery/jquery.js:3025
.ready@http://localhost:9000/bower_components/jquery/jquery.js:398
completed@http://localhost:9000/bower_components/jquery/jquery.js:93
http://localhost:9000/bower_components/ember-data/ember-data.js
Line 3285
错误的详细信息是:
error(error=TypeError: this.modelFor(...) is undefined
return this.get('store').find('story', this.modelFor('story').id);
, transition=Object { router={...}, promise=Promise, data={...}, more...}, originRoute=<Getbookmarks.StoryEditRoute:ember265> { routeName="story_edit", router=<Getbookmarks.Router:ember266>, store=<Getbookmarks.Store:ember267>, more...})ember.js (line 33949)
triggerEvent(handlerInfos=[Object { isDynamic=false, name="application", handler=<Getbookmarks.ApplicationRoute:ember268>, more...}, Object { isDynamic=false, name="story_edit", handler=<Getbookmarks.StoryEditRoute:ember265>}], ignoreFailure=true, args=[
TypeError: this.modelFor(...) is undefined
我不知道为什么我会这样做。我跟着tutyorial,我没有跳过任何东西。我担心的是该教程的版本有些陈旧,但代码是从ember生成器生成的。
有什么想法吗?
编辑:
这是模型的生成代码:
Getbookmarks.StoryEditRoute = Ember.Route.extend({ model:function(params){ return this.get('store')。find('story',this.modelFor('story')。id); }, setupController:function(controller,model){ controller.set('model',model); buffer = model.get('attributes')。map(function(attr){ return {key:attr.get('key'),value:attr.get('value')} }); controller.set('buffer',buffer) } });
路线: Getbookmarks.Router.map(function(){
this.resource('index',{path:'/'}); this.resource('story',{path:'/ story /:story_id'}); this.resource('story_edit',{path:'/ story / new'});
});
答案 0 :(得分:1)
昨天我按照同样的指南遇到了同样的问题。这似乎是路线的一个问题,因为故事编辑需要一个story_id,我们无法将它用于新故事。我设法像这样解决了这个问题,在没有story_id的情况下为story_new添加了一条新路线:
在routes.js中:
this.resource('story_edit', { path: '/story/edit/:story_id' });
this.resource('story_new', { path: '/story/new' });
然后清空StoryEditController(否则应用程序会抱怨“需要:'故事'”,此外它将在以后更换)并在routes / story_new_route.js中添加:
Getbookmarks.StoryNewRoute = Ember.Route.extend({
renderTemplate: function() {
var controller = this.controllerFor('storyEdit');
this.render('storyEdit', { controller: controller } );
}
});
这个新控制器将重定向到storyEdit控制器并使用storyEdit-Template。然后清空story_edit_route.js(我们现在将使用默认值),你的app应该运行。
希望这也适合你,否则只需告诉我,我就可以提供更多细节。