【发布时间】:2018-04-07 14:29:25
【问题描述】:
我在这里创建了一个 plunker:http://plnkr.co/edit/zGqouwzxguef13lx48iP?p=preview
当我在日视图中单击 ui-grid 的一个单元格时,什么也没有发生。我所期望的是执行测试功能并显示带有文本“测试”的警报,但事实并非如此。
这里出了什么问题?
这是ui-grid 3.0最新版本的html单元格模板:
HTML
<div ng-click="test()" ng-switch="row.entity[row.grid.columns.indexOf(col)].isPeriod">
<div ng-switch-when="true">
<tabset>
<tab>
<tab-heading>
<i class="glyphicon glyphicon-book"></i>
</tab-heading>period id:
{{ row.entity[row.grid.columns.indexOf(col)].id}}
</tab>
<tab select="alertMe()">
<tab-heading>
<i class="glyphicon glyphicon-bell"></i>
</tab-heading>
{{row.entity[row.grid.columns.indexOf(col)].content}}
</tab>
</tabset> <!-- PeriodTemplate -->
</div>
<div ng-switch-when="false">
<div>Hello empty template</div>
</div> <!-- EmptyPeriodTemplate -->
</div>
控制器:
'use strict';
angular.module('projectplanner').controller('DateplannerDayController', function ($scope, $state) {
var columnHeaderDates = ['col1','col2','col3','col4','col5','col6','col7']
$scope.columns = createColumnHeaders(columnHeaderDates);
var data = [{isPeriod: true, id: 10, rowNumber: 1},{isPeriod: false, id: 11, rowNumber: 2}]
$scope.test = function()
{
alert('test');
};
$scope.gridOptions = {
rowHeight: 200,
data: data,
enableSorting: false,
enableColumnMenu: false,
columnDefs: $scope.columns,
onRegisterApi: function (gridApi) {
$scope.gridApi = gridApi;
$scope.gridApi.core.addRowHeaderColumn(
{ name: 'rowHeaderCol',
displayName: '',
width: 100,
cellTemplate: '<div>row header template</div>'
});
}
};
function createColumnHeaders(columnHeaders) {
var columnDefinitions = [];
for (var i = 0; i < columnHeaders.length; i++) {
var column = {
name: columnHeaders[i],
cellTemplate: 'lessonplanner.day.celltemplate.html',
field: i + 'x'
}
columnDefinitions.push(column);
}
return columnDefinitions;
}
});
【问题讨论】:
-
使用外部作用域。在这里查看我的答案:stackoverflow.com/questions/26621598/…
-
@mainguy 这与 externalScopes 有什么关系?没有外部范围。来自 ui-grid 的 tut 侧的 ng-click 示例正在做同样的事情,就像我没有外部范围一样。嗯......这很奇怪,我可以发誓我已经看到这个 ng-click 在一个 cellTemplate 中工作在一个 plunker 上,但是 ui-grid 说:“UI-Grid 使用隔离范围,因此无法从行或单元格模板。”好的,那么我需要一个外部范围!!!谢谢哥们!
-
目前 ui-grid 的版本、教程和手册都是一团糟。我还认为不久前它在没有外部范围的情况下也可以工作。希望这能尽快退出测试版。顺便说一句:你在那里建造的令人印象深刻的 Plunker!
-
玩得开心,真正的应用更高级;-)