0
假設這構成了一個表:如何在Javascript中使用數組創建表格對象原型?
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乙
- 至少1行,但是可以無限期地進行迭代
- 1頁腳
我想要做的是爲「表」和行對象創建一個構造函數/原型函數,這樣我就可以通過增加索引號來循環「行」,而無需手動重寫/添加具有相同模式的行/表。
更新:要添加更多的上下文,this fiddle顯示我想迭代的「表」和「行」。
什麼你試過嗎? –
什麼問題? –
抱歉不清楚!基本上我想爲「表」創建一個構造函數/原型,這樣我就可以存儲「行」對象以及循環行,而無需手動重寫/添加具有相同模式的行。 –