【发布时间】:2011-10-24 19:09:10
【问题描述】:
我正在运行一个初始化抽象图形包的代码。创建图形实例后,我使用来自服务器的 get 请求获取数据,并希望更新图形数据提供者。问题是有时(对于 IE6-8)保存数据提供程序的对象尚未初始化,因此当我尝试更新数据时 javascript 崩溃。
如何在对象准备好之前延迟代码? 伪:
...
...
...
// Init code
$graph = new Graph();
...
...
...
// GET request
$.getJSON(..., ..., function(data) {
...
...
...
// Make sure that $graph.series[0] is ready
// Should not use while, but something similar in functionality
while (!($graph.series && $graph.series[0]))
; // Sleep the code until object is ready
// Set the dataprovider after init complete
$graph.series[0].setData(data);
...
...
...
});
...
...
...
问候
【问题讨论】:
标签: javascript jquery internet-explorer cross-browser internet-explorer-6