如何在Javascript中使用数组创建表对象原型?

如何在Javascript中使用数组创建表对象原型?,javascript,arrays,prototype-programming,Javascript,Arrays,Prototype Programming,假设这构成一个表: rows: [ //TABLE 1 { //TABLE 1 TITLE HEADER cells: [ {value: ""}, {value: "Table 1", textAlign: "center", bold: "true"}

假设这构成一个表:

rows:
            [
                //TABLE 1
                { //TABLE 1 TITLE HEADER
                    cells: [
                    {value: ""},
                    {value: "Table 1", textAlign: "center", bold: "true"}
                    ]
                },
                { // Header A
                    cells: [
                    {value: ""},
                    {value: "Month", textAlign: "center", verticalAlign: "center", background: "rgb(198,217,241)", bold: "true"},
                    {value: "Metric", textAlign: "center", bold: "true"},
                    {value: ""},
                    {value: "Achievement (%)", textAlign: "center", verticalAlign: "center", bold: "true"},
                    {value: "Weight  (%)", textAlign: "center", bold: "true"},
                    ]
                },
                { // Header B
                    cells: [
                    {value: ""},
                    {value: ""},
                    {value: "Plan", textAlign: "center", background: "rgb(192,0,0)", bold: "true", color:"white"},
                    {value: "Actual", textAlign: "center", background: "rgb(0,176,80)", bold: "true", color:"white"},
                    {value: ""},
                    {value: "50", textAlign: "center", background: "rgb(198,217,241)"}]
                },
                { // Table1 row1
                    cells: [
                    {value: ""},
                    {value: "1", textAlign: "center"},
                    {value: "", textAlign: "center", background: "rgb(242,220,219)"},
                    {value: "", textAlign: "center", background: "rgb(235,241,222)"},
                    {value: "", textAlign: "center", background: "rgb(198,217,241)", bold:"true"},
                    { value: "", textAlign: "center", background: "rgb(198,217,241)", bold:"true"}]
                },
                { // Table1 row2
                    cells: [
                    {value: ""},
                    {value: "2", textAlign: "center"},
                    {value: "", textAlign: "center", background: "rgb(242,220,219)" },
                    {value: "", textAlign: "center", background: "rgb(235,241,222)"},
                    {value: "", textAlign: "center", background: "rgb(198,217,241)", bold:"true"},
                    {value: "", textAlign: "center", background: "rgb(198,217,241)", bold:"true"}]
                }
                { // FOOTER
                    cells: [
                    {value: ""},
                    {value: "Average per month", textAlign: "center", background: "rgb(198,217,241)", bold:"true"},
                    {value: ""},
                    {value: "", textAlign: "center", background: "rgb(198,217,241)", bold:"true"},
                    {value: "", textAlign: "center", background: "rgb(198,217,241)", bold:"true"},
                    {value: "", textAlign: "center", background: "rgb(255,192,0)", bold:"true"}]
                }
            ]
假设一个表由多行组成,如何为表和行创建对象原型,以便可以用多行迭代多个表实例

  • 1标题标题
  • 1个收割台A和1个收割台B
  • 至少1行,但可以无限期迭代
  • 1英尺
我想做的是为“table”和rows对象创建一个构造函数/原型函数,这样我就可以通过增加索引号来循环“rows”,而无需手动重新写入/添加具有相同模式的行/表


更新:要添加更多上下文,请显示我要迭代的“表”和“行”。

类似此类实现的内容:

var Tabel=(函数(){
函数选项卡(参数){
如果(params==void 0){params={};}
this.table=(params.table==void 0?document.createElement(“表”):params.table);
if(params.attributes!=void 0){
for(参数属性中的变量键){
if(params.attributes.hasOwnProperty(键)){
var attribute=参数属性[key];
this.table.setAttribute(键,属性);
}
}
}
this.thead=this.table.appendChild(document.createElement(“thead”);
this.tbody=this.table.appendChild(document.createElement(“tbody”);
this.tfoot=this.table.appendChild(document.createElement(“tfoot”);
this.rows=(params.rows==void 0?[]:params.rows)
.排序(功能(a、b){
变量A=(A.headOrFoot==无效0?0:(A.headOrFoot?1:-1));
VarB=(B.headOrFoot==无效0?0:(B.headOrFoot?1:-1));
返回B-A;
});
这个。render();
}
Tabel.prototype.render=函数(){
cancelAnimationFrame(this.renderHandle);
this.renderHandle=requestAnimationFrame(this._render.bind(this));
};
Tabel.prototype.\u render=函数(){
this.thead.innerHTML=this.tbody.innerHTML=this.tfoot.innerHTML=“”;
对于(var rowIndex=0;rowIndexdocument.body.appendChild(t1.表)您尝试了什么?问题是什么?对不起,不清楚!基本上,我想为“表”创建一个构造函数/原型,这样我就可以存储“行”对象并循环行,而无需手动重写/添加具有相同模式的行。