function listFiles() {
var x = document.getElementById("ResultShown").value;
var date = new Date();
date.setDate(date.getDate() - 180);
var n = date.toISOString().split('.')[0] ;
var test = false;
gapi.client.drive.files.list({
pageSize: x,
q: "starred = "+test+" and viewedByMeTime < '"+n+"'",
orderBy: 'quotaBytesUsed desc',
fields: "nextPageToken, files(id, name, viewedByMeTime, mimeType, quotaBytesUsed, webViewLink)",
}
).then(function(response) {
var table = document.getElementById('content');
appendPre('Files:');
appendRow(table, ['Name', 'Last Viewed', 'Link', 'Size'], 'th');
var files = response.result.files;
var table = document.getElementById('content');
if (files && files.length > 0) {
for (var i = 0; i < files.length; i++) {
var file = files[i];
appendRow(table, [
file.name +" ",
file.viewedByMeTime.split('.')[0]+" ",
link(file.webViewLink),
file.quotaBytesUsed + ' bytes'
])
}
} else {
appendPre('No files found.');
}
});
}
目前,每次我点击按钮激活此功能时,都会出现一个新列表,我可以添加哪个列表,使按钮清除旧列表,然后再放一个新列表?
编辑#1: 在这个屏幕截图中,你可以看到每次我按下一个按钮来调用列表文件功能时,会出现一个新列表,而不是有一百万个列表,我希望每次清除按钮时它都会清除旧列表和用新列表替换它
我只希望一次展示一件事。
答案 0 :(得分:1)
在向表元素添加新行之前,您可以删除表元素中除标题行之外的所有行:
var table = document.getElementById('content');
var rows = table.rows;
while (rows.length > 1) rows[1].parentNode.removeChild(rows[1]);
appendPre('Files:');
appendRow(table, ['Name', 'Last Viewed', 'Link', 'Size'], 'th');
function listFiles() {
var x = document.getElementById("ResultShown").value;
var date = new Date();
date.setDate(date.getDate() - 180);
var n = date.toISOString().split('.')[0];
var test = false;
gapi.client.drive.files.list({
pageSize: x,
q: "starred = " + test + " and viewedByMeTime < '" + n + "'",
orderBy: 'quotaBytesUsed desc',
fields: "nextPageToken, files(id, name, viewedByMeTime, mimeType, quotaBytesUsed, webViewLink)",
}
).then(function(response) {
var table = document.getElementById('content');
var files = response.result.files;
var table = document.getElementById('content');
var rows = table.rows;
while (rows.length > 1) rows[1].parentNode.removeChild(rows[1]);
if (files && files.length > 0) {
for (var i = 0; i < files.length; i++) {
var file = files[i];
appendRow(table, [
file.name + " ",
file.viewedByMeTime.split('.')[0] + " ",
link(file.webViewLink),
file.quotaBytesUsed + ' bytes'
])
}
} else {
appendPre('No files found.');
}
});
}
注意:这个答案可能看起来不合时宜,因为它建立在我对additional questions OP has asked关于同一项目的答案的基础上。