Action handlers implemented directly on controllers are deprecated -how to correct this?

前端 未结 2 849
忘掉有多难
忘掉有多难 2021-02-12 20:32

I just upgraded from ember.js RC7 to RC8 and found that a simple template (shown below) would throw a deprecated warning

\"Action handlers implemented di

相关标签:
2条回答
  • 2021-02-12 20:57

    You should define your actions inside the actions hash in the controllers, views and routes to favour consistency.

    Refer this https://github.com/emberjs/ember.js/pull/3091

    Demo Fiddle

    App.ApplicationController = Em.ObjectController.extend({
      actions : {
       // your actions here
      }       
    });
    
    0 讨论(0)
  • 2021-02-12 21:03

    It looks like I just needed to give the PR a look that changed this :)

    In my controller I just needed to move the addPerson / deletePerson under actions like so

    App.PeopleController = Ember.ArrayController.extend({                                                                  
        actions: {                                                                                                         
            addPerson: function() {                                                                                        
                var person = {                                                                                             
                    firstName: this.get('firstName'),                                                                      
                    lastName: this.get('lastName')                                                                         
                };                                                                                                         
                App.Person.add(person);                                                                                    
            },                                                                                                             
            deletePerson: function(person) {                                                                               
                App.Person.remove(person);                                                                                 
            }                                                                                                              
        }                                                                                                                  
    });
    
    0 讨论(0)
提交回复
热议问题