我打算为所有列调用相同的函数。我尝试了许多不同的方式来调用函数。没有一个起作用。我确定我做了一些愚蠢的事情。如果有人可以纠正我。
$scope.gridOptions = {
enableSorting: true,
columnDefs: [
{ field: 'name',
//cellClass: howCanIhaveCommonFunction()
},
{ field: 'company',
//cellClass: howCanIhaveCommonFunction()
}
]
};
// below function this would be common for all columns
var howCanIhaveCommonFunction = function(grid, row, col, rowRenderIndex, colRenderIndex)
{
if (grid.getCellValue(row,col) === 'Velity' || grid.getCellValue(row,col) === 'Beryl Rice' ) {
return 'blue';
}
return 'red';
}
最佳答案
是的,这是一个简单的错误,您没有只说函数名称,而是在没有任何参数的情况下调用它。
$scope.gridOptions = {
enableSorting: true,
columnDefs: [
{ field: 'name',
cellClass: howCanIhaveCommonFunction
},
{ field: 'company',
cellClass: howCanIhaveCommonFunction
}
]
您只需通过 () 使所有参数为空,只需传递函数名称,ui-grid 将使用正确的参数调用它。
关于javascript - 在 UI-Grid 中调用 cellClass 函数的通用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31308951/