【问题标题】:Access handsontable methods/properties using nghandsontable使用 nghandsontable 访问 handsontable 方法/属性
【发布时间】:2015-04-04 12:05:42
【问题描述】:

我正在为Handsontable 使用ngHandsontable Angular 指令。我设法成功地显示了数据,但我很难访问修改后的行,以便将数据发送到数据库。
我尝试绑定 afterChange 回调,但列排序后索引似乎关闭。 (显示在表格中显示的行的索引,而不是在数据源中)

我想知道保存 ngHandsontable 数据的最佳做法是什么,或者我应该怎么做才能访问 getData 方法或 columnSorting 属性等 API

非常感谢您的帮助! - 马可

【问题讨论】:

  • 我调查了这个问题并试图找到解决方案。不幸的是,这变得非常困难,因为 ngHandsontable 的文档至少可以说是可怕的。我建议您发布一些示例代码来显示您的问题或创建一个 plnkr 来显示您到目前为止的进度。我现在能找到的只是 this git 问题,它只是模糊地描述了一个可能的解决方案。

标签: angularjs handsontable


【解决方案1】:

我最终使用 afterInit 事件来获取实例,然后在 afterChange 等其他事件中调用方法。

这就是我的代码的样子:

afterInit: function() {
        $scope.hot.instance = this;
    }

然后:

afterChange: function (changes, source) {
        if (source != 'loadData') {          
            var hot = $scope.hot.instance;
            var dataRow = hot.getSourceDataAtRow(index)
            // .... saveChanges...
        };
    }

非常感谢 Bricktop 给我的提示。

【讨论】:

    【解决方案2】:

    我只是用这种逻辑解决了它:

    post: function postLink(scope, iElement, iAttrs, controller) {
        var hotDiv = iElement.find("div[hot-table]")
    
        var hotInstance = hotDiv.isolateScope().hotInstance;
        hotInstance.addHook('afterLoadData', function(){
            console.log("loaded data");
        });
    }
    

    【讨论】:

      【解决方案3】:

      只需在控制器中使用视图模型

      var vm = this;
      

      然后您可以调用此视图模型的任何核心可操作方法,例如

      this.getCell()
      
      this.getSourceDataAtRow()
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-05-07
        • 1970-01-01
        • 2011-08-11
        • 2012-09-25
        • 1970-01-01
        相关资源
        最近更新 更多