Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
countnazgul
Contributor III
Contributor III

'SetOnUpdateComplete' called multiple times

Hi all,

im building QV object extension but it have very strange behaviour. Im in the beggining of the development process and so far the extension itself is very simple

  • get the current document
  • get 'LB03' object
  • wait until the object is finished
  • get the object values
  • display this values in the extension and color them based on their state

The problem is that for some reason when i select values anywhere on the document `SetOnUpdateComplete` function is being called multiple times (usually 3 times) and this makes my object to be re-drawn multiple times as well which leads to some "flickering" - at one moment i can see the old values (with the selection state before the selection), then i can see all values (old and new) and finally i can see the new values

Any idea why this is happening?

        var finalHTML = ''

        var doc = Qv.GetCurrentDocument();

        var lb = doc.GetObject("LB03");


        $('#' + divName).html('');

        lb.SetOnUpdateComplete(function (d) {

            console.log(1)

            $('#' + divName).html('');

            for (var i = 0; i < lb.Data.Rows.length; i++) {

                $('#' + divName).html('');

                var dataRow = lb.Data.Rows[0]


                var style = '';


                if (dataRow.state == 'Selected') {

                    style = ' background-color: green ';

                } else {

                    style = ' background-color: gray ';

                }


                finalHTML += '<div style="' + style + '">' + dataRow.text + '</div>'

            }


           $('#' + divName).html(finalHTML);

        })

Regards!

Stefan

5 Replies
bc-thebruuu
Creator
Creator

Hi

Did you find a solution?

I have a problem which seem related ...

I have SetOnUpdateComplete on the whole document (qv.document) and sometime the event is thrown but objects on the page are not fully drawn ?!

countnazgul
Contributor III
Contributor III
Author

Still havent found why is this happening

bc-thebruuu
Creator
Creator

Does the behaviour change if you use a button with a select in field?

The selection in an object may be related to several mouse click, each one throwing a select value event ...

MVW
Contributor III
Contributor III

Just want to post this for future reference:

When a GetObject is called, it creates an Object Manager, which is attached to the list of Managers in the Document Manager list. This List gets notified whenever anything changes in the document (eg selections). So basically any selection will generate a refresh and a subsequent callback of every object you have gotten via GetObject.

I have seen suggestions on setting the callback to only run once by using a variable, but that still keeps an ever growing list of Object Managers tied to document selections and will make the document slower and more unstable over time.

What you could do is to remove the object manager from the list of document managers at the end of the callback. It doesn't get it out of the memory, but it will not be listening to any events in the document anymore. (for example this.DocumentMgr.RemoveFromManagers(this.ObjectMgr) at the end of your callback.

MikeW
Creator
Creator

Actually, I should have said remove from both Managers and Members at the end of the callback.

this.DocumentMgr.RemoveFromManagers(this.ObjectMgr);
this.DocumentMgr.RemoveFromMembers(this.ObjectMgr);