本文介绍了就绪事件不能按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遗漏了什么?
我试图实现ready事件处理程序,基本上是从指南复制,但是我不能让它工作。 function drawVisualization(){
...
...
...
table = new google.visualization.Table(document.getElementById('table1'));
table.draw(dataTable,{width:1100});
google.visualization.events.addListener(table,'ready',resizeTable);
}
function resizeTable(){
alert('Will this work?');
}
//此代码不会产生警报
解决方案
从google docs :
准备 图表已准备好进行外部方法调用。如果您想要与图表进行互动,并在绘制图表后调用方法,则应该在之前为此事件设置侦听器,然后调用绘图方法,并且仅在事件触发后调用它们。
因此,您必须将代码的顺序更改为:
...
table = new google.visualization.Table(document.getElementById('table1'));
google.visualization.events.addListener(table,'ready',resizeTable);
table.draw(dataTable,{width:1100});
...
I have tried to implement the ready event handler, basically copying from the Guide however I cannot get it to work.
What am I missing?
function drawVisualization() {
...
...
...
table = new google.visualization.Table(document.getElementById('table1'));
table.draw(dataTable, {width: 1100});
google.visualization.events.addListener(table, 'ready', resizeTable);
}
function resizeTable() {
alert('Will this work?');
}
//This code does not produce an alert
解决方案
From google docs about Table events:
ready The chart is ready for external method calls. If you want to interact with the chart, and call methods after you draw it, you should set up a listener for this event before you call the draw method, and call them only after the event was fired.
So, you have to change order of code to:
...
table = new google.visualization.Table(document.getElementById('table1'));
google.visualization.events.addListener(table, 'ready', resizeTable);
table.draw(dataTable, {width: 1100});
...
这篇关于就绪事件不能按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!