简体   繁体   English

销毁视图并重新加载相同的视图

[英]destroy view and reload same view

I have run into an issue where I need to completely destroy and remove a component within my view, because the 3rd party items in the component need a full page refresh to function correctly. 我遇到了一个问题,我需要完全销毁并删除视图中的某个组件,因为该组件中的第三方项目需要整页刷新才能正常运行。 The component will only update when the parent view changes to completely different view or if the page is refreshed. 仅当父视图更改为完全不同的视图或刷新页面时,组件才会更新。 Is it possible to completely remove an ember component from the parent view and then rerender it with the newly updated model information from the parent view? 是否可以从父视图中完全删除余烬组件,然后使用父视图中新近更新的模型信息将其重新呈现?

App.VideoPlayerComponent = Em.Component.extend({
      initPlayer: function(){
            //player stuff here 
            //updates video url yet previous video DOM garbage remains
      }.observes('url'),

      didInsertElement: function(){
            this.initPlayer();
      }
});

The video player im using is thePlatform js PDK which seems to be made for only static websites >: 我正在使用的视频播放器是thePlatform js PDK,它似乎仅适用于静态网站>:

You can use this.rerender(); 您可以使用this.rerender();

It will redraw the current view / component. 它将重绘当前视图/组件。 Also note that willDestroy() will be called too. 还要注意, willDestroy()也将被调用。

Know more about it here 在这里了解更多

Update 1 更新1

You have to use the something like this to find the element on which you want to attach plugin 您必须使用类似这样的内容来找到要附加插件的元素

this.$().find("#my-video-element");

You also have to define code to destroy the video player element in the willDestroy hook. 您还必须定义代码以销毁willDestroy挂钩中的视频播放器元素。 This will make sure video player is removed on rerender. 这将确保视频播放器在重新渲染时被删除。

App.VideoPlayerComponent = Em.Component.extend({
      initPlayer: function(){
            //player stuff here 
            //updates video url yet previous video DOM garbage remains
      }.observes('url'),

      didInsertElement: function(){
            this.initPlayer();
      },

      willDestroyElement : function(){
           //here you need code that video plugin provide to destroy the video attached
           this.$().find("#my-video-element").destory("video")  
      }

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM