0

I am using one function which contains some data processing concept.that means processing the "OData" (accessing remote data from URL -service).

bindTo: function () {

        if(!sf.util.isNullOrUndefined(this.model.Series))
        {
            for (var i = 0; i < 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 && series.dataSource.data.length > 0) {

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

                 }
             } 

            }
        }
    },

Please refer below processoData function

_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();**
            });
    },

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.

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.

http://api.jquery.com/jQuery.when/

i tried like below code.

$.when(this.bindTo()).then(function(e) {
            chart.Draw();
        });

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

so bindto 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.

4

0 回答 0