Prevent Re-Rendering Views

Is there a way to tell Ember not to redraw the views?

A simple option:

I have a list of clients that populates dynamically. By clicking on the client in the list, go to the client details page. When I click back, I want to be exactly in the same place on the customer list.

Usually Ember re-displays the view (when I switch to a different state), and my previous position is lost.

+4
source share
1 answer

I hate being the bearer of bad news, but you cannot stop re-rendering with ember if you switch to another part of the application. If it is no longer visible, the elements have been removed from the DOM and no longer exist.

I solved this problem in my applications using jQuery to get the scroll position of a page or object. jQuery Scroll Up . I did what I had a place on the model that kept the scroll position. Then I looked like something

didInsertElement: function() { //Restore previous scroll position $('#item').scrollTop( this.get('model.scrollPosition') ); /* or on older ember builds `this.getPath('model.scrollPosition')` */ //Update the model with new scroll position when user scrolls var _self = this; $('#item').scroll(function(e){ _self.get('model').set('scrollPosition', $(this).scrollTop()); }); } 

The key conclusion here is that the views should re-render. This does not stop. Your job as a developer is to save all the state you need to view (scroll position, item with focus, etc.) so that it can be restored. Ember gives you the tools to do this.

+1
source

Source: https://habr.com/ru/post/1433078/


All Articles