繁体   English   中英

在UI-Grid中调用cellClass函数的通用函数

[英]Calling common function for cellClass Function in UI-Grid

我打算为所有列调用相同的函数。 我尝试了许多不同的方式来调用函数。 没有工作。 我确信我做了些傻事。 如果有人能纠正我。

$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';
  }

http://plnkr.co/edit/4yjVbhmfR47cf7FGfyFk?p=preview

是的,这是一个简单的错误,而不是只说函数名称,而是在没有任何参数的情况下调用它。

$scope.gridOptions = {
enableSorting: true,
columnDefs: [
  { field: 'name', 
    cellClass:  howCanIhaveCommonFunction 
  },
  { field: 'company',
    cellClass:  howCanIhaveCommonFunction

  }
]

你刚刚通过使用那些()来使所有参数为null,只需传递函数名称,ui-grid将使用正确的参数调用它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM