callback function is inside another function in jquery
<p>I am using one function which contains some data processing concept.that means processing the "OData" (accessing remote data from URL -service). </p>

<pre><code>bindTo: function () {

        if(!sf.util.isNullOrUndefined(this.model.Series))
        {
            for (var i = 0; i &lt; this.model.Series.length; i++) {
             if (sf.util.isNullOrUndefined(this.model.Series[i].Visibility))
                    this.model.Series[i].Visibility = 'visible';
            var series = this.model.Series[i];
            if (sf.util.isNullOrUndefined(series.Points))
                series.Points = [];
             if (series.dataSource) {
                 if (series.dataSource.data instanceof sf.DataManagar) {
                     this._processOData(series);
                 } else if (series.dataSource.data != null &amp;&amp; series.dataSource.data.length &gt; 0) {

                     this._processJsonData(series.dataSource.data, series);
                     this.Draw();

                 }
             } 

            }



        }



    },
</code></pre>

<p>Please refer below processoData fuction</p>

<pre><code>_processOData: function(series) {
    var chart = this;
            var queryPromise = series.dataSource.data.executeQuery(series.dataSource.query);
            queryPromise.done(function (e) {
                chart._processJsonData(e.result,series);  

                **chart.Draw();**
            });
    },
</code></pre>

<p>we have to wait for some time to fetch data from URL so i used callback function here "done" function and then only i called draw function for chart.  but in other cases there is no need for accessing remote data that means i need to call the draw function directly. if it is a remote data processing i need to wait until i get data and then only am going to draw the chart but in other cases i don't need this condition.</p>

<p>so bindTo function which calls "Draw" function for chart. i need to some jquery function which waits/executes until call back completed like this below  jquery function.</p>

<p><a href="http://api.jquery.com/jQuery.when/" rel="nofollow">http://api.jquery.com/jQuery.when/</a></p>

<p>i tried like below code.</p>

<pre><code>$.when(this.bindTo()).then(function(e) {
            chart.Draw();
        });
</code></pre>

<p>but it didn't wait until callback function in bindTo to complete. its called draw function directly before processing <strong>"odata"</strong> </p>

<p>so <strong>bindto</strong> function is need to wait until the callback function which is inside the bind to function to complete and then only i need to call draw function.</p>

<p>Thanks,</p>

<p>Siva</p>
