目前,我将 slickgrid 包裹在指令中,这意味着我的 html 看起来像这样:
<div class="gridContainer" ng-controller="EditModalCtrl">
<div class="modalTest" style='width:100%;'>
<div style='width:100%;height:500px;' all-batches-grid></div>
</div>
</div>
在我的 slickgrid 指令中,我有:
angular.module('epDefaultApp.allBatchesDirective', [])
.directive('allBatchesGrid', [function () {
return {
restrict: 'EA',
link : function(scope, element, attrs){
grid.onDblClick.subscribe(function (e, args) {
$('.addButton').removeClass('addText');
$('#addEditButton').addClass('editButton');
$('.addButton').addClass('editText');
var item = grid.getDataItem(args.row);
scope.openPrefill('lg', item);
});
}
}
}]);
这也是我的控制器:
angular.module('epDefaultApp.editModalController', [])
.controller('EditModalCtrl', ['$scope', '$modal', '$log', 'toastr', function ($scope, $modal, $log, toastr) {
$scope.openPrefill = function (size, selectedRowObject) {
$scope.selectedRow = {
vendorName: selectedRowObject[0],
purchaseNumber: selectedRowObject[3],
invoiceAmount: selectedRowObject[6],
invoiceDate: selectedRowObject[10],
invoiceNumber: selectedRowObject[1],
dueDate: selectedRowObject[9],
checkCode: '0',
memo: selectedRowObject[5]
};
}]);
这样做的原因是指令中的范围变量实际上链接到 EditModalCtrl 中的 $scope。这发生在我们第一次在 HTML 文件中初始化 grid 指令时。