[英]Remove Quotes from json_encoded string value
我正在一個項目中,將jTable實現為PHP framwework類。 進展順利。 現在,我遇到了一個問題,我希望能夠在編輯對話框中進行自定義輸入。
我們已經在使用select2插件,現在我想在jTable的編輯對話框中實現它。 據我了解,可以將自定義字段添加到編輯對話框中,如下所示:
Name: {
title: 'Name',
width: '20%',
input: function (data) {
if (data.record) {
return '<input type="text" name="Name" style="width:200px" value="' + data.record.Name + '" />';
} else {
return '<input type="text" name="Name" style="width:200px" value="enter your name here" />';
}
}
}
注意上面的代碼在JavaScript中。 基本上,我要做的是在php數組中構建此javascript,並通過json_encode
將其發送到客戶端。
我的問題是當我這樣做時
$column_array['name']['input'] = function (data) {if ....and so on}
我站在javascript方面
input: "function (data) {... so on"
請注意雙引號,它是一個字符串而不是一個函數。
我需要的是在輸入后刪除這2個雙引號。 (到目前為止,這是我的想法)
或者,如果有人對jTable有一定的經驗,並且知道一種更好的方法來實現自定義字段,例如select2,selected,jQuery multiselect,elfinder和類似的東西。
我明天可以根據需要提供一些代碼,因為我今天不再工作。
基於此概念:
// Create a function that takes two arguments and returns the sum of those arguments
var fun = new Function("a", "b", "return a + b");
// Call the function
fun(2, 6);
Output: 8
您可以將JSON稍微更改為
Name: {
title: 'Name',
width: '20%',
input: { name: "input",
param: "data",
body: "if (data.record) {
return '<input type=\".... "
}
....
然后您可以定義一個函數並執行它
var d = new Function(Name.input.name, Name.input.param, Name.input.body);
d(otherdata);
這將忽略可怕的eval(...)
東西。 注意:它仍然不是給定對象的方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.