Maximum call stack size exceeded - When Trying to Empty ComboBox DataSource

Hello,

I am trying to empty the datasource of a combobox via javascript, but at the momento I try to do it I get the error Maximum call stack size exceeded

I need to empty the datasource to reload it with a new one, but something is not working well with the code.

This is the sample code:

(Empty the DataSource) document.getElementById("lstEmpenhos").ej2_instances[0].dataSource = []; (Fill the DataSource with another content)

document.getElementById("lstEmpenhos").ej2_instances[0].dataSource = EmpenhoList;

After running that code, the dropdown arrow on the combobox turns into an spinning wheel and I get the error mentioned above.

 

Is there a solution for this problem?

Regards,

Alexandre


3 Replies 1 reply marked as answer

VJ Vinitha Jeyakumar Syncfusion Team May 9, 2022 06:33 AM UTC

Hi Alexandre,


Your reported issue can be resolved by calling dataBind method after removing and adding the dataSource to the control. please check the code below,

Code snippet:
<div class="control-wrapper">
    <div id="default" style='padding-top:75px;'>
        <ejs-combobox id="games" dataSource="@ViewBag.data" placeholder="Select a game" popupHeight="220px">
        </ejs-combobox>
    </div>
    <ejs-button id="targetButton" content="Change"></ejs-button>
</div>
<script>
    window.onload = function () {
        document.getElementById('targetButton').onclick = function () {
           var comboObj = document.getElementById('games').ej2_instances[0];
           comboObj.dataSource = [];
           comboObj.dataBind();
           comboObj.dataSource =  ["Golf", "Gymnastics", "Hockey", "Tennis"];
           comboObj.dataBind();
        }
    }
</script>


Regards,
Vinitha

Marked as answer

AL Alexandre May 9, 2022 08:21 AM UTC

Hello Vinitha


The dataBind method solved my problem.


Thank  you!


Alexandre



VJ Vinitha Jeyakumar Syncfusion Team May 10, 2022 05:00 AM UTC

Hi Alexandre,


You are welcome. Please get back to us if you need any further assistance.

Regards,
Vinitha


Loader.
Up arrow icon