简体   繁体   English

如何将 javascript 函数分配给使用 php 呈现的制表符格式化程序?

[英]How to assign a javascript function to a tabulator formatter rendered with php?

I am using php to create the tabulator column definition array and I would like to assign a javascript function.我正在使用 php 创建制表符列定义数组,我想分配一个 javascript 函数。 This does not work:这不起作用:

array_push($row2['formatter']='function(cell, formatterParams){var pType = cell.getValue();if(pType == "Patient"){cell.getElement().style.background = "yellow";}return pType;}');

I can assign the function to the array after using client side javascript.使用客户端 javascript 后,我​​可以将函数分配给数组。 This works:这有效:

tdata[0][1]['formatter']=function(cell, formatterParams){var pType = cell.getValue();if(pType == "Patient"){cell.getElement().style.background = "yellow";}return pType;};

Any help making this work on the server side with php would be greatly appreciated!任何使用 php 在服务器端完成这项工作的帮助将不胜感激!

I came up with this solution... I'm sure there is a better way to do it!我想出了这个解决方案......我相信有更好的方法来做到这一点!

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

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

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