Javascript 在Goldenlayout中使用Slickgrid数据视图
我可以在GoldenLayout中将Slickgrid与普通网格一起使用 但是,我正在尝试实现Dataview,但onRowCountChanged.subscribe事件出现问题:Javascript 在Goldenlayout中使用Slickgrid数据视图,javascript,slickgrid,golden-layout,Javascript,Slickgrid,Golden Layout,我可以在GoldenLayout中将Slickgrid与普通网格一起使用 但是,我正在尝试实现Dataview,但onRowCountChanged.subscribe事件出现问题: var StockGridComponent = function (container, state) { this._dataView = new Slick.Data.DataView(); this._container = container; this._state = state;
var StockGridComponent = function (container, state) {
this._dataView = new Slick.Data.DataView();
this._container = container;
this._state = state;
this._grid = null;
this._columns = [...];
this._data = data;
container.on('open', this._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());
this._dataView.onRowCountChanged.subscribe(function (e, args) {
console.log(this); <-- return DataView
this._grid.updateRowCount(); <-- error: "Uncaught TypeError: Cannot read property 'updateRowCount' of undefined"
this._grid.render();
}
);
var StockGridComponent=函数(容器、状态){
这个._dataView=new Slick.Data.dataView();
这个._容器=容器;
这个。_state=状态;
这是。_grid=null;
此项。_列=[…];
这个。_data=数据;
容器上('open',this.\u createGrid,this);
};
StockGridComponent.prototype.\u createGrid=函数(){
这个。_网格=新的光滑网格(
此._container.getElement(),
这是.\u dataView,
这是.\u列,
这是你的选择
);
这个.u grid.setSelectionModel(新的Slick.CellSelectionModel());
此._dataView.onRowCountChanged.subscribe(函数(e,args){
console.log(this);对我来说更像是一个上下文问题。在\u createGrid
方法中,在变量中定义外部this
的上下文并使用它。
像
StockGridComponent.prototype.\u createGrid=function(){
这个。_网格=新的光滑网格(
此._container.getElement(),
这是.\u dataView,
这是.\u列,
这是你的选择
);
这个.u grid.setSelectionModel(新的Slick.CellSelectionModel());
var self=this;//存储上下文并稍后使用
此._dataView.onRowCountChanged.subscribe(函数(e,args){
console.log(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();
}
);