在视图中,是否有一种简单/自动的方法可以从列表中的所有数据中生成表?

时间:2018-07-12 15:05:57

标签: asp.net-mvc

我有20列以上的列表,感觉不像手动构建import tkinter as tk class Example(): def __init__(self): root = tk.Tk() self.lb = tk.Listbox(root, width=10) self.text = tk.Text(root) self.lb.pack(side="left", fill="y") self.text.pack(side="right", fill="both", expand=True) self.current = None self.notes = {} self.lb.bind("<<ListboxSelect>>", self.show_item) def show_item(self, event=None): selection = self.lb.curselection() if selection: index = selection[0] title = self.lb.get(index) # save current note if self.current: self.notes[self.current] = self.text.get("1.0", "end-1c") # show new item self.current = title self.text.delete("1.0", "end") self.text.insert("1.0", self.notes[title]) def add_note(self, title, body): self.notes[title] = body self.lb.insert("end", title) example = Example() example.add_note("note one", "this is the body of note one") example.add_note("Note with a really long title", "this is the body of the note with a long title") example.add_note("x", "this is the body of note x") tk.mainloop() <th>。是否有一种简单/自动的方法来告诉MVC生成具有所有数据在特定列表中的基本表?

1 个答案:

答案 0 :(得分:1)

如何使用jQuery DataTables?

https://datatables.net/examples/data_sources/js_array.html

视图将如下所示

@model  string[]

<script>
    var dataSet = [
        [@string.Join("], ", Model.Select(o => o))] // convert model to array data, you could also use a serializer here
    ];

    $(document).ready(function () {
        $('#example').DataTable({
            data: dataSet,
            columns: [
                { title: "My strings" }
            ]
        });
    });
</script>

<table id="example" class="display" width="100%"></table>