5

一个如何{{row.getProperty(col.field)}}进入ng-click?发生的情况是 id 没有被传播回来,但网格使用 id 正确渲染。

代码:

var app = angular.module('testing',['ngGrid']);
app.config(['$locationProvider', function($locationProvider)  
{  
       $locationProvider.html5Mode(true);
}]);    

app.controller('TestCtrl',function($scope)  
{  
      $scope.details = []; //whatever dummy data  
      $scope.loadById = function(id)  
      {  
            $window.location.href= 'newPage/?id='+id;
      };  

      $scope.gridOptions =  
      {  
           data: 'details',  
           columnDefs:[{field:'id',DisplayName:'id',  
                 cellTemplate:'<div class="ngCellText" ng-class="col.colIndex()"><a ng-click="loadById({{row.getProperty(col.field)}})">{{row.getProperty(col.field)}}</a></div>'  
              }]
      };    
});  
4

1 回答 1

14

您可以只在 ng-click 中传递 row,而不仅仅是双括号表达式输出的值。

你的 cellTemplate 变成了这个

cellTemplate:'<div class="ngCellText" ng-class="col.colIndex()"><a ng-click="loadById(row)">{{row.getProperty(col.field)}}</a></div>' 

你的功能变成了这个

$scope.loadById = function(row) {  
   window.console && console.log(row.entity);
   $window.location.href= 'newPage/?id='+ row.entity.id;
};  
于 2013-11-07T10:18:17.543 回答