ngHandsontable显示在休息服务呼叫没有内容 [英] ngHandsontable shows no content on rest service call

查看:202
本文介绍了ngHandsontable显示在休息服务呼叫没有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了很多不同的方式来获得一个ngHandsontable得到一个休息的服务工作。

我媒体链接到处找得到任何的例子...不幸的是所有的例子都只是使用静态变量的定义和对数据没有服务电话。具有该用例人工作的例子?


解决方案

这可能是有点晚了你,但我有假货使用功能的REST服务的例子。
您可以修改它放在一个真正的REST调用来代替。
http://plnkr.co/edit/GPYTdJ

\r
\r

函数MainCtrl($范围){\r
  this.settings = {\r
\r
  };\r
  this.data = [\r
    [年,起亚,尼桑,丰田,本田]\r
    [2008,10,11,12,13],\r
    [2009,20,11,14,13],\r
    [2010,30,15,12,13]\r
  ];\r
  VAR认为这=;\r
  $ scope.fakeRestRequest =功能(){\r
    VAR restData = [\r
      [年,起亚,马自达,丰田,本田]\r
      [2018,13,41,12,13],\r
      [2019,23,41,14,13]\r
      [2020,33,45,12,13]\r
    ];\r
    that.data = restData;\r
  };\r
}\r
\r
角\r
  .module('应用',['ngHandsontable'])\r
  .controller('MainCtrl',MainCtrl);\r
  

\r

<!DOCTYPE HTML>\r
< HTML数据-NG-应用=应用程序>\r
\r
< HEAD>\r
  <脚本SRC =HTTPS://$c$c.angularjs.org/1.4.5/angular.js>< / SCRIPT>\r
  &LT;脚本src=\"https://cdnjs.cloudflare.com/ajax/libs/handsontable/0.19.0/handsontable.full.js\"></script>\r
  &LT;脚本src=\"https://cdnjs.cloudflare.com/ajax/libs/ngHandsontable/0.7.0-beta3/ngHandsontable.js\"></script>\r
\r
  &LT;链接rel =stylesheet属性HREF =htt​​ps://cdnjs.cloudflare.com/ajax/libs/handsontable/0.19.0/handsontable.full.css/&GT;\r
\r
&LT; /头&GT;\r
\r
&LT;机身NG控制器=MainCtrl作为CTRL&GT;\r
  &LT; H2&GT; Handsontable REST#1问题&LT; / H&GT;\r
\r
    &LT; D​​IV ID =网格&GT;\r
        &LT;热表\r
          COL-标题=真\r
          行标题=假\r
          数据行=ctrl.data\r
          设置=ctrl.settings&GT;\r
        &LT; /热表&gt;\r
    &LT; / DIV&GT;\r
    \r
    &LT;按钮式=按钮NG点击=fakeRestRequest()&GT;更新数据&LT; /按钮&GT;\r
    \r
&LT; /身体GT;\r
\r
&LT; / HTML&GT;

\r

\r
\r

I'm trying in a lot of different ways to get a ngHandsontable to get working with a rest service.

I've allready searched everywhere to get any example... unfortunately all examples are just using static variable definitions and no service calls for the data. Has anybody a working example for that use case?

解决方案

This might be a bit late for you but I have an example that fakes a REST service using a function. You can modify it to put in a real REST call instead. 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>

这篇关于ngHandsontable显示在休息服务呼叫没有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆