ngHandsontable没有显示休息服务电话的内容

时间:2015-01-28 19:57:29

标签: angularjs handsontable

我正在尝试通过多种方式获得ngHandsontable来使用休息服务。

我已经到处搜索任何一个例子......不幸的是,所有的例子都只是使用静态变量定义而没有服务调用数据。有没有人为这个用例做一个工作的例子?

1 个答案:

答案 0 :(得分:0)

这对你来说可能有点晚了,但我有一个使用函数伪造REST服务的例子。 您可以修改它以放入真正的REST调用。 http://plnkr.co/edit/GPYTdJ

function MainCtrl($scope) {
  this.settings = {

  };
  this.data = [
    ["Year", "Kia", "Nissan", "Toyota", "Honda"],
    ["2008", 10, 11, 12, 13],
    ["2009", 20, 11, 14, 13],
    ["2010", 30, 15, 12, 13]
  ];
  var that = this;
  $scope.fakeRestRequest = function () {
    var restData = [
      ["Year", "Kia", "Mazda", "Toyota", "Honda"],
      ["2018", 13, 41, 12, 13],
      ["2019", 23, 41, 14, 13],
      ["2020", 33, 45, 12, 13]
    ];
    that.data = restData;
  };
}

angular
  .module('app', ['ngHandsontable'])
  .controller('MainCtrl', MainCtrl);
  
<!DOCTYPE html>
<html data-ng-app="app">

<head>
  <script src="https://code.angularjs.org/1.4.5/angular.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/handsontable/0.19.0/handsontable.full.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/ngHandsontable/0.7.0-beta3/ngHandsontable.js"></script>

  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/handsontable/0.19.0/handsontable.full.css" />

</head>

<body ng-controller="MainCtrl as ctrl">
  <h2>Handsontable Stackoverflow REST Question</h2>

    <div id="grid">
        <hot-table
          col-headers="true"
          row-headers="false"
          datarows="ctrl.data"
          settings="ctrl.settings">
        </hot-table>
    </div>
    
    <button type="button" ng-click="fakeRestRequest()">Update Data</button>
    
</body>

</html>