在JS的agGrid中显示二维数组

时间:2019-09-23 10:19:43

标签: javascript arrays grid ag-grid

我试图在我的JavaScript作业之一中添加agGrid。其实我有一个二维数组

import wx

class Myframe(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None)
        self.my_choices = {"Choose a sport":0,"Board Sports":1,"Ball Sports":2,"Fight Sports":3}
        #self.my_choices = ["Board Sports","Ball Sports","Fight Sports"]
        self.my_subchoices = [[],["Skate boarding","Surfing","Ski boarding"],["Football","Cricket","Rugby"],["Boxing","Wrestling","Karate"]]
        pan = wx.Panel(self)
        self.cbx = wx.ComboBox(pan, -1, value = "Choose a sport", pos=(10,30), size=(300,30),choices=list(self.my_choices),style=wx.CB_DROPDOWN | wx.CB_READONLY )
        self.cbx.Bind(wx.EVT_COMBOBOX, self.on_selection)

    def on_selection(self, evt):
        Choice = self.cbx.GetSelection()
        msg = ""
        #
        # Ignore choice 0 because of style wx.CB_READONLY or include a blank entry
        # for choice 0 in my_subchoices
        for x in self.my_subchoices[Choice]:
            msg += x+"\n"
        self.cbx.SetToolTip(msg)

if __name__ == "__main__":
    App = wx.App()
    Myframe().Show()
    App.MainLoop()

我想按原样显示在agGrid中。例如

enter image description here

还希望显示上图中显示的行标题和列标题。寻找建议。

1 个答案:

答案 0 :(得分:2)

ag-Grid期望rowData是对象的数组,并且columnDefs中的field属性指定用于检索特定列的数据的键。

幸运的是,在JS中,除了基元之外,所有东西几乎都是对象。因此,您可以引用数组索引,就好像它们是对象的字符串等效项一样。

var obj = {"0": "First item"};
var first1 = obj[0];
var arr = ["First item"];
var first2 = arr[0];
first1 === first2;

这是一个带有示例的Plunker: https://next.plnkr.co/edit/bdBBcEmd9hRDLn93