diff --git a/static/js/table.js b/static/js/table.js new file mode 100644 index 0000000..776d4e3 --- /dev/null +++ b/static/js/table.js @@ -0,0 +1,49 @@ +function Table(columns, data, actions, elementId) { + this.columns = columns + this.data = data + this.actions = actions + this.element = $(elementId) +} + +Table.prototype.Generic = function () { + let self = this + // 创建表格元素 + let $table = $('
' + col + ' | '); + }); + // 如果有操作按钮,添加操作列 + if (self.actions.length > 0) { + $theadRow.append('操作 | '); + } + $thead.append($theadRow); + $table.append($thead); + + // 创建表体 + let $tbody = $('
---|---|
' + cell + ' | '); + }); + // 如果有操作按钮,添加操作单元格 + if (self.actions.length > 0) { + let $actionTd = $('');
+ self.actions.forEach(function(action) {
+ let $button = $('');
+ $button.on('click', function() {
+ action.onClick(row);
+ });
+ $actionTd.append($button);
+ });
+ $tr.append($actionTd);
+ }
+ $tbody.append($tr);
+ });
+ $table.append($tbody);
+ // 将表格添加到目标元素中
+ self.element.html($table);
+}
\ No newline at end of file
diff --git a/view/user.html b/view/user.html
index 9ad6ad7..079c0ff 100644
--- a/view/user.html
+++ b/view/user.html
@@ -2,9 +2,41 @@
{{end}}
{{define "content"}}
-User-User page content goes here. + {{end}} {{define "script"}} + + {{end}} \ No newline at end of file |