简体   繁体   English

Javascript:我正在尝试在模式内部创建动态表格以进行摊销

[英]Javascript: I am trying to create dynamic table inside modal for amortization

i am trying to create a dynamic table for amortization table but i coudnt append column. 我正在尝试为摊销表创建动态表,但是我很想追加列。 it insert row everytime so my every value is in new row and how do i create loop so that my next column should be +1. 它每次都插入行,所以我的每个值都在新行中,以及如何创建循环,以便我的下一列应为+1。 because this is row(0) so it everytime comes upward and my whole table shows upside down. 因为这是row(0),所以每次它都向上,而我的整个表都倒过来显示。

i write so far 我到目前为止写

function writeln(str) {
  var output = document.getElementById("output");
  var txt = document.createTextNode(str);
  var row = output.insertRow(0);
  var cell1 = row.insertCell(0);
  cell1.innerHTML = str;
}
function main() {
  for (var i = 1; i <= numpayments; ++i) {
    sumpay += payments;
    propertypriceapp = 0.0090 + propertypriceapp;
    var thisint = balance * intrate;
    sumint += thisint;

    var thisprin = payments - thisint;
    sumprin += thisprin;

    balance -= thisprin;

    var curvalequity = sumprin * (1 + propertypriceapp);

    writeln(flushright(i, 5));
      // flushright(fmtmoney(payments), 9) + "  " + 
      // flushright(fmtmoney(thisint), 9) + "  " + 
      // flushright(fmtmoney(thisprin), 8) + "  " + 
      // flushright(fmtmoney(sumpay), 9) + "  " + 
      // flushright(fmtmoney(sumint), 9) + "  " + 
      // flushright(fmtmoney1(sumprin), 9) + "  " + 
      // flushright(fmtmoney(balance), 12) + "   " +
      // flushright(fmtmoney1(curvalequity), 9) + "  " +
      writeln(flushright(fmtmoney1(propertypriceapp), 9));
    // write("----------------------------------------------------------------------------------------------------------------------")
    // writeln("")
  }
}

my html code is 我的html代码是

<table class="modal-body" id="output">
        </table>

Your writeln function create 1 row and 1 column each time, when it called. 您的writeln函数每次调用时都会创建1行和1列。

It have 1 var, that is unusable - var txt = document.createTextNode(str); 它有1个var,无法使用var txt = document.createTextNode(str); and each time make a call to DOM - var output = document.getElementById("output"); 并每次调用DOM- var output = document.getElementById("output"); It is bad for performance, and code is very difficult to understand. 这对性能不利,并且代码很难理解。

If you want to create more colums in 1 row, your code must be something like this: 如果要在一行中创建更多列,则您的代码必须是这样的:

var output = document.getElementById("output");

function writeln(str) {
    // str -> must be array, that have lenght = num of columns, you want to create
    var row = output.insertRow(0),
        len = str.lenght; // count of rows
    // creates rows 
    for (var i = 0; i < len; i++) {
        // create new row
        var cell = row.insertCell(i);
        // insert HTML code in it
        cell.innerHTML = str[i];    
    }
}

If you want to create more rows with columns, you must make it in the loop, and each time change j param in var row = output.insertRow(j), line. 如果要使用列创建更多行,则必须使其在循环中,并且每次在var row = output.insertRow(j), line中更改j参数。

This is the solution for above question, str is converted into array 这是上述问题的解决方案,str转换为数组

temp = str.split(" "); // this will split string into ","

after that the array used to create a cell < td> 之后,用于创建单元格的数组<td>

var table=document.createElement('TABLE');
table.setAttribute('class','table table-striped table-bordered')//this is bootstraps classes
var tbdy=document.createElement('TBODY');
table.appendChild(tbdy);
function writeln(str) {
  var output = document.getElementById("output");
    var temp = new Array();
    temp = str.split("  ");
     var tr=document.createElement('TR');
     tbdy.appendChild(tr);
     for (var zxc2=0;zxc2<temp.length;zxc2++){
      var td=document.createElement('TD');
      td.appendChild(document.createTextNode(temp[zxc2]));
      tr.appendChild(td);
    }
  output.appendChild(table);
}

this way i got my solution. 这样我得到了解决方案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JavaScript中的年金摊销表 - Annuity amortization table in JavaScript 我正在尝试在Javascript中转换动态公式 - I am trying to convert a dynamic formula in Javascript 我正在尝试使用 javascript 从 JSON 文件创建动态 html 选项 - I am trying to create dynamic html options from a JSON file using javascript 我试图在画布中插入一张桌子 - i am trying to insert a table inside the canvas 我正在尝试使用JavaScript创建一个计算器。 - I am trying to create a calculator with javascript. 我正在尝试在 javascript 中使用 for 循环来创建一个显示 * 的表,并且对于每一行,列增加 1 * - I am trying to use a for loop in javascript to create a a table that displays * and for each row the columns increase by 1 * 我正在尝试创建一个动态表。 我想得到的行数等于用户在框中输入的数量 - I am trying to create a dynamic table. i want to get the number of rows equal to the number that user enters in the box 我正在尝试在反应中使用 ref 访问模态(mui 模态)内的元素,但对元素的引用是 null - I am trying to access element inside modal(mui modal) using ref in react but reference to element is null 如何使用 Javascript 创建具有动态信息的模态? - How do I create a modal with dynamic information using Javascript? 尝试使用香草Javascript创建动态表,代码无法正常工作 - Trying to create a dynamic table with vanilla Javascript, code not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM