Simple ContainerView causes “Using the defaultContainer is no longer supported.”

后端 未结 1 483
既然无缘
既然无缘 2021-01-21 04:45

With latest Ember, the following simple ContainerView causes the error:

DEPRECATION: Using the defaultContainer is no longer supported. [defaultContainer#

1条回答
  •  清歌不尽
    2021-01-21 05:19

    That deprecation message reference this gist, if you look the migration paths: (WIP) section, it have the following text:

    if you are creating views outside the context of a parentView (this may not be recommended, but it is happening) you will want to make sure to instantiate your view via the container itself.

    this.container.lookup('view:apple')
    // will provide a instance of apple view.
    

    So you need to update your code to use the container instead of App.FooView.create().

    App.IndexController = Ember.Controller.extend({
      show: function() {    
        var v = this.container.lookup('view:foo');    
        v.appendTo(App.rootElement);
      }
    });
    

    Depending of your version, you will receive a new warning message:

    DEPRECATION: Action handlers implemented directly on controllers are deprecated in favor of action handlers on an actions object (show on )

    In that case put your action in a actions object:

    App.IndexController = Ember.Controller.extend({
      actions: {
        show: function() {    
          var v = this.container.lookup('view:foo');    
          v.appendTo(App.rootElement);
        }
      }  
    });
    

    This is a updated jsbin using the lastest ember version without warnings http://jsbin.com/uqawux/4/edit

    0 讨论(0)
提交回复
热议问题