我可以在GoldenLayout中使用Slickgrid和普通网格。
但是,我正在尝试实现Dataview,而我遇到了onRowCountChanged.subscribe事件的问题:
#!/usr/bin/env python
import os
import sys
import threading
class fifo_buffer(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.dict_buffer = {}
def run(self):
print("run() starts.")
path = "./sample.fifo"
fifo = open(path, "r")
count = 0
for line in fifo:
count = count + 1
self.dict_buffer[count] = line
print("in for expression: before show_dict()")
self.show_dict() # you could process dict_buffer here, but obviously this dict changes over time, and you could only access the lines that run() thread has already processed.
#print str(count) + " -> " + self.dict_buffer[count]
fifo.close()
print("run() completes.")
def get_packet(self, index):
return self.dict_buffer[index]
def len_dict(self):
print("Length dict: " + str(len(self.dict_buffer)))
def show_dict(self):
print(self.dict_buffer)
def main():
fb = fifo_buffer()
fb.start()
# fb.join()
# print("get_packet(2): " + fb.get_packet(2))
# you could process dict_buffer here, but you could only process/access the lines which run() thread has already processed.
fb.len_dict()
fb.show_dict()
if __name__ == "__main__":
main()
我认为我的问题是我不知道如何引用回到对象的_grid对象(我不熟悉Javascript)。
任何使用带有SlickGrid Dataview的Goldenlayout的人都可以分享他们创建SlickGrid组件的方式吗?
谢谢。
答案 0 :(得分:0)
对我来说似乎更像是一个上下文问题。在_createGrid
方法中,在变量中定义外部this
的上下文并使用它。
像
StockGridComponent.prototype._createGrid = function () {
this._grid = new Slick.Grid(
this._container.getElement(),
this._dataView,
this._columns,
this._options
);
this._grid.setSelectionModel(new Slick.CellSelectionModel());
var self = this; // store the context and use later
this._dataView.onRowCountChanged.subscribe(function (e, args) {
console.log(this); <-- this here will refer to context of callback method
self._grid.updateRowCount();
self._grid.render();
}
);
希望这可以解决问题。