簡體   English   中英

如何將 javascript 函數分配給使用 php 呈現的制表符格式化程序?

[英]How to assign a javascript function to a tabulator formatter rendered with 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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM