javascript - 如何将 javascript 函数分配给用 php 呈现的制表符格式化程序?
问题描述
我正在使用 php 创建制表符列定义数组,我想分配一个 javascript 函数。这不起作用:
array_push($row2['formatter']='function(cell, formatterParams){var pType = cell.getValue();if(pType == "Patient"){cell.getElement().style.background = "yellow";}return pType;}');
使用客户端javascript后,我可以将函数分配给数组。这有效:
tdata[0][1]['formatter']=function(cell, formatterParams){var pType = cell.getValue();if(pType == "Patient"){cell.getElement().style.background = "yellow";}return pType;};
非常感谢使用 php 在服务器端进行这项工作的任何帮助!
解决方案
我想出了这个解决方案......我相信有更好的方法来做到这一点!
function returnFunc(value, index, array){
if (value['formatter']){
if (value['formatter'].indexOf("function")>-1){
return value['formatter']=eval("(" + value['formatter'] + ")");
}
}
}
tdata[0].map(returnFunc);
推荐阅读
- macos - 对于 macOS Cocoa,如何在屏幕上指定一个窗口或一个矩形来截取屏幕截图?
- mysql - SQL查询-找出用户第一天收入大于该用户收入的所有日期
- google-apps-script - 如何在保持工作表只读的同时允许用户单击按钮
- html - 将图像与html中三个列的中间图像水平对齐
- sql - 当另一列 = '已接受' (SQL) 时,如何对一列求和
- wordpress - Wordpress 从插件更改页面、帖子的标题..
- php - Symfony 和 Twig:自定义 exception_controller 不适用于生产
- php - 如何在 MYSQL 中计算 WordPress order_itemmeta 的产品 _qty 的 SUM()
- python - 如何从请求中提取值?
- azure - Azure 认知搜索突出显示修剪