Soy un novato en la codificación, algo de experiencia en python. Nuestra empresa (Finanzas) está utilizando un software llamado Xceptor para procesar los datos y agregar la función de incluir la tabla en el cuerpo del mensaje con HTML. Pero una cosa que realmente me molesta es que cuando no hay información en Listfield , solo quiero generar texto y no mostrar la tabla. Muestra el encabezado y el contenido cuando hay algo, incluida una oración que indica cuántos. ¿Es posible? Aquí está el script de muestra. Funciona bien en el editor de la escuela W3, pero la parte del script no funciona en la plataforma que estoy usando. ¿Alguien tiene alguna sugerencia al respecto? Gracias por su ayuda y que tenga una buena.
<table border="1" id="MyTable"> <p id="count"></p> <tr> <th>Record Type</th> <th>Trade Date</th> <th>Account</th> <th>Transaction</th> <th>Traded Asset</th> <th>Proceed CCY</th> <th>Settlement Date</th> <th>Quantity Traded</th> <th>SHORTNAME</th> <th>ACCT_ID</th> </tr> {[List Field]} </table> <script> var rowCount = document.getElementById("myTable").rows.length; if(rowCount <= 1 ) { document.getElementById("myTable").style.display = "none"; } else{ document.getElementById("count").innerHTML = "There are "+(rowCount-1) +"row(s)";} </script>Las cadenas de identidad distinguen entre mayúsculas y minúsculas. Lo escribiste mal en tu versión. Con document.getElementById("MyTable"); funcionará:
const tbl = document.getElementById("MyTable"), rows=tbl.rows.length-1 if(rows) document.getElementById("count").innerHTML = `There ${rows==1?"is one row":`are ${rows} rows`}`; else tbl.style.display="none"; <p id="count"></p> <table border="1" id="MyTable"> <tr> <th>Record Type</th> <th>Trade Date</th> <th>Account</th> <th>Transaction</th> <th>Traded Asset</th> <th>Proceed CCY</th> <th>Settlement Date</th> <th>Quantity Traded</th> <th>SHORTNAME</th> <th>ACCT_ID</th> </tr> <tr> <td>Type</td> <td>Trade Date</td> <td>Account</td> <td>Transaction</td> <td>Traded Asset</td> <td>Proceed CCY</td> <td>Settlement Date</td> <td>Quantity Traded</td> <td>SHORTNAME</td> <td>ACCT_ID</td> </tr> {[List Field]} </table>HTML es un lenguaje de marcado y no un lenguaje de programación, por lo que no puede usar declaraciones if en HTML. Deberá hacerlo con la ayuda de Javascript.