首页 > 解决方案 > 如何将 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 在服务器端进行这项工作的任何帮助!

标签: javascriptphptabulator

解决方案


我想出了这个解决方案......我相信有更好的方法来做到这一点!

function returnFunc(value, index, array){
        if (value['formatter']){
            if (value['formatter'].indexOf("function")>-1){
                return value['formatter']=eval("(" + value['formatter'] + ")");
            }
        }
}
tdata[0].map(returnFunc);

推荐阅读