2017-06-29 24 views
0

GoldenLayoutの通常のグリッドでSlickgridを使用できます。GoldenlayoutでのSlickgrid Dataviewの使用

しかし、私は、データビューを実装しようとしていると私はonRowCountChanged.subscribeイベントとのトラブルを抱えている:

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(); 
    } 
); 

私は私の問題は、私は、オブジェクトの_gridに戻って参照する方法がわからないと思いオブジェクト(私はJavascriptに堪能ではない)。

SlickGrid DataviewでGoldenlayoutを使用している人は、SlickGridコンポーネントの作成方法を共有できますか?

ありがとうございます。

答えて

0

私には文脈の問題のようです。 _createGridメソッドでは、変数outerにthisのコンテキストを定義し、それを使用します。 Like

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(); 
    } 
); 

希望すると、この問題が解決されます。

+0

右、シンプルですっきりした、ありがとう! – jackofnone

+0

ようこそ@jackofnone –

関連する問題