我正在嘗試創建一個web應用程序來處理任意大小的數字的二維矩形表。每個表格將成爲一個文檔(將存儲在一個集合中,並由用戶彼此共享)。最後,我想擴展到任意數量的維度,但2D已經給我帶來了麻煩。目前,我的數據存儲爲如何對Meteor中的輸入單元格表格進行反應式綁定?
{dimensions: [2,3],
data: [2, 3, 5, 7, 11, 13]}
,但我認爲這將是更容易編寫UI代碼爲陣列
[[2, 3, 5],
[7, 11, 13]]
的數組,很容易足以讓我在其他地方進行這種轉變。
我一直致力於玩具實現,將我的頭部纏繞在反應部件周圍,而不會增加Collections和用戶帳戶的複雜性。硬編碼的2x3版本是在https://github.com/scentoni/meteor-grid和https://github.com/scentoni/meteor-grid/tree/loopcell雙{{#each}}
循環的版本,其中關鍵的一點是
<table>
<tbody>
{{#each rows}}
<tr>
{{#each cols}}
<td><input class="cell" name="{{../row}},{{col}}" type="text" value="{{stuff ../row col}}"/></td>
{{/each}}
</tr>
{{/each}}
</tbody>
</table>
和
var iota = function (n) {return Array.apply(null, {length: n}).map(Number.call, Number); }
Template.page.rows = function() {
return iota(Session.get('numrows')).map(function (x) {return {row: x};});
};
Template.page.cols = function() {
return iota(Session.get('numcols')).map(function (x) {return {col: x};});
};
Template.page.stuff = function (i, j) {
return Session.get('data')[i][j];
};
這似乎是工作,但我覺得我」誤用這些工具。任何人都可以爲我提供一些指導嗎?