Fetching remote view - option to remove previous views?

3 posts, 0 answers
  1. MattM
    MattM avatar
    5 posts
    Member since:
    Jul 2012

    Posted 24 Jul 2012 Link to this post

    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. MattM
    MattM avatar
    5 posts
    Member since:
    Jul 2012

    Posted 24 Jul 2012 Link to this post

    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?
  3. Kendo UI is VS 2017 Ready
  4. Jonathan
    Jonathan avatar
    37 posts
    Member since:
    Jul 2012

    Posted 24 Jul 2012 Link to this post

    A method to clear previously loaded views would be nice.
Back to Top