This is a migrated thread and some comments may be shown as answers.

Fetching remote view - option to remove previous views?

2 Answers 74 Views
Application
This is a migrated thread and some comments may be shown as answers.
MattM
Top achievements
Rank 1
MattM asked on 24 Jul 2012, 11:23 AM
Kendos,

I'm writing a fairly complex app using the framework. The app uses a page input form with many complex elements. This page is fetched via ajax using the application navigate methods.

The issue is that this appends the main document. So each time you call a slightly different version of this page (edit, etc) it fetches the HTML via Ajax and appends it to the current document.

This not only vastly increases the size of the document (and possibly leading to memory issues if the app is open for long enough) but also it confuses the DOM as there are now 2 or more versions of the form, so you get 2 or more copies of ID elements.

I'd like a way to 'clean up' all previously loaded views when fetching a new page. I've managed to fudge this in my code by putting this in the data-init function of the form I'm loading:

$('div[data-role=view]').each( function( i, elem )
            {
                if ( $(elem).attr('data-url') && $(elem).attr('data-url') != window.location.hash.replace( /#/, '' ) )
                {
                    $(elem).remove();
                }
            } );

But it seems less that optimal and prone to bugs down the road.

Something to consider for a future version?

2 Answers, 1 is accepted

Sort by
0
MattM
Top achievements
Rank 1
answered on 24 Jul 2012, 11:27 AM
Also,

When creating modal boxes, it seems to add them to the document.body (km-shim). This means again, when creating these modal boxes, the main document gets longer and longer each time the page is called.

I've had to manually clean these up too.

/* Now remove old shims */
            $('li._statements').each( function( i, elem )
            {
                var _thisId = $(elem).parents('.km-modalview').attr('id');
                 
                _ids[ _thisId ] = _thisId;
            } );
             
            $.each( _ids, function( _i, _elem )
            {
                var ids = $( '[id="' + _i + '"]' );
             
                if ( ids.length > 1 )
                {
                    $(ids[0]).parents('.km-shim').remove();
                }
            });


Perhaps they could be attached to the view to make clean up easier?
0
Jonathan
Top achievements
Rank 1
answered on 24 Jul 2012, 05:25 PM
A method to clear previously loaded views would be nice.
Tags
Application
Asked by
MattM
Top achievements
Rank 1
Answers by
MattM
Top achievements
Rank 1
Jonathan
Top achievements
Rank 1
Share this question
or