Sending array to server: Too much recursion

asked 2021-01-30 01:52:49 +0800

Jtt gravatar image Jtt
107 4

updated 2021-01-30 02:07:30 +0800


I've been working in a text-comparison module. I had to do some modifications as we want our users to download certain files from official sources and compare them with the version we have on our databse. This official docs added some sort of 'tags' to notify about updates, so that's the work I've been on. Now the module works as intended but I have to align all the paragrahps so the user can see what was compared with what.

I've done this with javascript (getBoundingClientRect) and padding and results are good, but in some documents, the script is long enough to "hang" the browser a little. I addded a popup warning while the comparison code is running to alert the users, but I'm looking for a way to avoid this. So my immediate answer was to align them using the server muscle. My idea was to send two arrays of Span elements to the server using zkbind.$().command, as per this example but the result is a Javascript error (title related) pointing to zk.wpd file, particularely to the array validation condition.

The document I'm using as a base case isn't one of the long ones that hanged the browser, so this tells me there is something else I'm either doing wrong (I'm fairly new to both Js and Zk. Loving them tho) or some other thing. Also, since this error isn't in my new script, I don't know if I can do something about it. Could you help me figure out what's going on? Thank you!

Code related:

Original alignment script (That hangs the browser):

function alinear(){
    var o = $(".izSec"); 
    var c = $(".drSec"); 
    for(var i = 0; i < o.length; i++){
        var oh = o[i].getBoundingClientRect().top;
        var ch = c[i].getBoundingClientRect().top;
        if(ch > oh){
            o[i].style.padding = ch-oh + "px 0px 0px 0px";
        } else if(oh > ch){
            c[i].style.padding = oh-ch + "px 0px 0px 0px";

New script (That throws the error):

function alinear(){
    var o = $(".izSec"); 
    var c = $(".drSec");
    var c1 = [];
    for(var i = 0; i<o.length; i++){
    zkbind.$("$comp").command('alinearSecciones', {or: o, ca: c1});

image description

This is where Firebug is reporting the exception to be thrown image description

This is as far as the trace goes

Any extra info you need, please ask!

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2021-02-01 16:40:49 +0800

MDuchemin gravatar image MDuchemin
2560 1 6
ZK Team

Hi there,

In the case of the 2nd script you are using these two lines:

var o = $(".izSec"); 
zkbind.$("$comp").command('alinearSecciones', {or: o, ca: c1});

In this case, the object "o" is a ZK enhanced jQuery selector, not an array. Since it's an object, ZK command binder tries to serialize it as a JSON string.

However, ZK enhanced JQuery selector hold a property that refers to their matching ZK selector, and vice-versa: zk('.something') == jq(".something").zk jq('.something') == zk(".something").jq

While this is convenient for object access in general, here, it causes the issue that you are encountering. As part of the jq('.something') object JSON string, the command binder tries to include the value of jq.$("something").zk, which itself contains the value jq.$("something").zk.jq Endless loop, JavaScript error.

So, to fix this issue:

Instead of passing the selector, you can just pass the content array of the selector. Either using the same method applied to the c1 object, or using o.toArray()

link publish delete flag offensive edit


I see! I wasn't aware of it at all, and it makes a lot of sense. Thank you! I'll try the alternatives you've suggested.

Jtt ( 2021-02-02 23:23:24 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

1 follower



Asked: 2021-01-30 01:52:49 +0800

Seen: 10 times

Last updated: Feb 01 '21

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More