google.setOnLoadCallback with jQuery $(document).ready(), is it OK to mix?

后端 未结 4 1609
不思量自难忘°
不思量自难忘° 2020-11-30 23:59

I\'m using Google Ajax API and they suggest I use google.setOnLoadCallback() to do various things related to their API but I\'m using also jQuery\'s $(doc

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 00:25

    Sorry to be raising this from the dead, but 1) It still comes up as an 'answer' to this problem and 2) I've found a better solution.

    There is an optional 3rd argument on the google.load function that takes an object of configuration options. One of the options is callback. It also gets rid of the need for a separate setOnLoadCallback call.

    E.g.

    google.load('visualization', '1.0', {
        'packages': "charttype", 
        'callback': $jQ.proxy(me.setupChart, me)
    });
    

    So:

    
    
    

    See: https://developers.google.com/loader/#Dynamic

提交回复
热议问题