使用ngHandsontable将数据绑定到视图

时间:2014-10-29 12:50:58

标签: angularjs angularjs-directive handsontable

我正在使用ngHandonstable指令和绑定数据,如下所示:

<div class="col-sm-9" id="plastic" ng-cloak ng-init="dataLoad()">
<hot-table settings="{colHeaders: colHeaders, contextMenu: ['row_above', 'row_below', 'remove_row'], afterChange: afterChange, fillhandle : fillHandle}"
           rowheaders="true"  minsparerows="minSpareRows"    datarows="db.lens" height="300"    width="700">
    <hot-column data="code" title="'Code'" type="grayedOut" readonly></hot-column>
    <hot-column data="description" title="'Description'" width="250" type="grayedOut" readonly></hot-column>
    <hot-column data="lastCost" title="'Previous Price'" type="grayedOut" readonly width="100"></hot-column>
    <hot-column data="currentCost" title="'Current Price'" type="'numeric'" width="100" format="'0,0.00 '"></hot-column>
    <hot-column data="percentageChange" title="'% Increase'" type="'numeric'" width="120" format="'% 0,0.00'" fillhandle="vertical"></hot-column>
</hot-table>

在我的控制器中,我有以下代码:

 app.controller('plasticController', ['$scope', '$location',  'toaster', 'plasticService', function ($scope, $location,  toaster, plasticService) {
    $scope.minSpareRows = 0;
    $scope.colHeaders = true;
    $scope.fillHandle = true;

    $scope.db = [];
   var dataLoad2 = function() {
        plasticService.getPlastic().then(function(results) {
            $scope.db = results.data;
            $scope.totalItems = results.totalCount;
            $scope.currentPage = results.currPage;
            $scope.totalPages = results.totalPages;

        }, function(error) {
            //alert(error.data.message);
        });
    };

我的视图未显示控制器中的任何数据。当使用json数据完成异步调用时,如何将数据推送到UI?

1 个答案:

答案 0 :(得分:2)

属性datarows应该是db而不是db.lens,因为你当前有

datarows="db"