我想到了!
我只需要移动我的位置:
// 应用查询语言语句。query.setQuery('SELECT A');
在 sendAndDraw 函数之外。
最终的JS如下:
var isFirstTime = true;
var options = {'showRowNumber': true};
var data;
var queryInput;
// To see the data that this visualization uses, browse to
// http://spreadsheets.google.com/pub?key=rYQm6lTXPH8dHA6XGhJVFsA
var query = new google.visualization.Query(
'https://docs.google.com/a/umbc.edu/spreadsheet/ccc?key=0Akd-rqu1ZR70dDYxUEtFdGVadENqN09kT01pdklRbXc&pli=1#gid=0');
// Apply query language statement.
query.setQuery('SELECT A');
function sendAndDraw() {
// Send the query with a callback function.
query.send(handleQueryResponse);
}
function handleQueryResponse(response) {
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
data = response.getDataTable();
var table = new google.visualization.Table(document.getElementById('querytable'));
table.draw(data, {'showRowNumber': false});
if (isFirstTime) {
init();
}
}
function setQuery(queryString) {
// Query language examples configured with the UI
query.setQuery(queryString);
sendAndDraw();
queryInput.value = queryString;
}
google.setOnLoadCallback(sendAndDraw);
function init() {
isFirstTime = false;
(new google.visualization.Table(document.getElementById('table'))).draw(data, options);
queryInput = document.getElementById('display-query');
}
function setQueryFromUser() {
setQuery(queryInput.value);
}