p5.js中p5.Table的clearRows()方法用于清除表中的所有行。它不会影响列及其标题。它可以用于清除表而不影响其列结构。它没有参数。语法:
clearRows()
参数:此函数没有参数。
以下示例说明了p5.js中的clearRows()函数:
javascript
function setup() {
createCanvas(500, 300);
textSize(16);
getColBtn = createButton("Get Table Row Details");
getColBtn.position(30, 50);
getColBtn.mouseClicked(getTableRows);
getColBtn = createButton("Clear Rows");
getColBtn.position(30, 80);
getColBtn.mouseClicked(clearAllRows);
text("Click on the button to clear the"+
" rows in the table", 20, 20);
// Create the table
table = new p5.Table();
// Add columns
table.addColumn("author");
table.addColumn("book");
// Add two rows
let newRow = table.addRow();
newRow.setString("author", "Marcel Proust");
newRow.setString("book", "In Search of Lost Time");
newRow = table.addRow();
newRow.setString("author", "James Joyce");
newRow.setString("book", "Ulysses");
}
function clearAllRows() {
clear();
text("Click on the button to clear"+
" the rows in the table", 20, 20);
// Use the clearRow() method to
// clear all rows in the table
table.clearRows();
text("All rows cleared!", 20, 140);
}
function getTableRows() {
clear();
text("Click on the button to clear the rows "+
"in the table", 20, 20);
// Display all the rows present in the table
text("There are " + table.getRowCount() +
" rows in the table", 20, 140);
for (let i = 0; i < table.getRowCount(); i++) {
let rowContents = table.rows[i].arr.toString();
text("Row " + i + ":" + rowContents, 20, 160 + i * 20);
}
}
输出:
在线编辑: https://editor.p5js.org/
环境设置: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
参考: https://p5js.org/reference/#/p5.Table/clearRows
相关用法
- p5.js Table clearRows()用法及代码示例
- Lodash _.method()用法及代码示例
- Node.js Http2ServerRequest.method用法及代码示例
- Node.js http.IncomingMessage.method用法及代码示例
- Javascript dataView.getInt16()用法及代码示例
- Javascript RegExp toString()用法及代码示例
- Node.js URLSearchParams.has()用法及代码示例
- JavaScript Math cosh()用法及代码示例
- HTML DOM isEqualNode()用法及代码示例
- JavaScript Date toLocaleTimeString()用法及代码示例
- Node.js crypto.createHash()用法及代码示例
- Node.js writeStream.clearLine()用法及代码示例
- Javascript Number isSafeInteger()用法及代码示例
- Node.js fs.link()用法及代码示例
- JavaScript Math random()用法及代码示例
- JavaScript Math round()用法及代码示例
- Javascript toString()用法及代码示例
- Javascript Number.isInteger( )用法及代码示例
- Javascript Number.isFinite()用法及代码示例
- Javascript toFixed()用法及代码示例
- Javascript toPrecision()用法及代码示例
- JavaScript Math abs()用法及代码示例
注:本文由纯净天空筛选整理自sayantanm19大神的英文原创作品 p5.js | p5.Table clearRows() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。