gpt4 book ai didi

ember.js - Ember Controller : nothing handled the action

转载 作者:行者123 更新时间:2023-12-03 06:40:31 25 4
gpt4 key购买 nike

我浏览了相关帖子几个小时,但找不到正确的答案来解决我遇到的问题。

我不断收到错误:

Uncaught Error: Nothing handled the action 'edit'. If you did handle the action, this error can be caused by returning true from an action handler in a controller, causing the action to bubble.

我认为 Controller 处理错误,或者它冒泡到错误的路线?

App.EventDetailsController = Ember.ObjectController.extend({
isEditing: false,

actions: {
edit: function() {
this.set('isEditing', true);
},

doneEditing: function() {
this.set('isEditing', false);
}
}
});


App = Ember.Application.create();

App.Router.map(function() {
// put your routes here
this.route('events', {path: '/events'});
this.route('createevent', {path: '/createevent'});
this.route('eventdetails', {path: ':eventdetails_id'});
});

App.EventsRoute = Ember.Route.extend({
model: function() {
return events;
}
});

App.EventDetailsRoute = Ember.Route.extend({
model: function(params) {
return events.findBy('id', params.eventdetails_id);
}
});

有人知道为什么这不起作用吗?

最佳答案

您可能想像这样定义您的路线:

App.Router.map(function() {
this.resource('events', function() { // /events <-- your event listing
this.resource('event', {path: ':event_id'}, function() { // /events/1 <-- your event details
this.route('edit'); // /events/1/edit <-- edit an event
});
this.route('create'); // /events/create <-- create your event
});
});

但除此之外,请注意操作会通过路由向上冒泡,因此请尝试将操作处理程序移至 EventDetailsRoute。

在这里阅读指南中谈论它的部分:http://emberjs.com/guides/templates/actions/#toc_action-bubbling

App.EventDetailsRoute = Ember.Route.extend({
actions: {
edit: function() {
this.set('isEditing', true);
},

doneEditing: function() {
this.set('isEditing', false);
},

//or maybe better:
toggleEditing: function() {
this.toggleProperty('isEditing');
}
},

model: function(params) {
return events.findBy('id', params.eventdetails_id);
}
});

关于ember.js - Ember Controller : nothing handled the action,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28710066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com