ember.js – 灰烬控制器:没有处理动作

前端之家收集整理的这篇文章主要介绍了ember.js – 灰烬控制器:没有处理动作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我看了几个小时的相关帖子,但找不到正确的答案来解决我遇到的问题.

我一直收到错误

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.

我认为控制器处理错误,或者它正在冒泡到错误的路线?

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);
    }
});
原文链接:https://www.f2er.com/js/157849.html

猜你在找的JavaScript相关文章