简体   繁体   English

从json_encoded字符串值中删除引号

[英]Remove Quotes from json_encoded string value

I am working on a project to implement jTable into a PHP framwework class. 我正在一个项目中,将jTable实现为PHP framwework类。 It is going quite well. 进展顺利。 Now I am stuck at a problem where I would like to be able to make custom input fieds on the edit dialog. 现在,我遇到了一个问题,我希望能够在编辑对话框中进行自定义输入。

We are already using the select2 plugin, now I want to implement this on the edit dialogs of jTable. 我们已经在使用select2插件,现在我想在jTable的编辑对话框中实现它。 As far as I understood it is possible to add custom fields to the edit dialog like this: 据我了解,可以将自定义字段添加到编辑对话框中,如下所示:

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" />';
        }
    }
}

Notice the code above is in JavaScript. 注意上面的代码在JavaScript中。 Basically what I do is that I build this javascript in php array and via json_encode I send it to the client. 基本上,我要做的是在php数组中构建此javascript,并通过json_encode将其发送到客户端。

My problem here is that when I do 我的问题是当我这样做时

$column_array['name']['input'] = function (data) {if ....and so on}

I get on the javascript side 我站在javascript方面

input: "function (data) {... so on"

Please notice the double quotes, it is a string and not a function anymore. 请注意双引号,它是一个字符串而不是一个函数。

What I would need is to remove this 2 double quotes after the input. 我需要的是在输入后删除这2个双引号。 (well that's my idea so far) (到目前为止,这是我的想法)

OR if any one got some experience with jTable] and knows a better way to implement custom fields like select2, chosen, jQuery multiselect, elfinder and stuff like that. 或者,如果有人对jTable有一定的经验,并且知道一种更好的方法来实现自定义字段,例如select2,selected,jQuery multiselect,elfinder和类似的东西。

I can give tomorrow some code if needed, cause I am not at work anymore today. 我明天可以根据需要提供一些代码,因为我今天不再工作。

Based on this concept: 基于此概念:

// 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

you may change your JSON a bit in to 您可以将JSON稍微更改为

Name: {
    title: 'Name',
    width: '20%',
    input: { name: "input",
             param: "data",
             body: "if (data.record) {
                   return '<input type=\".... "
            }
    ....

then you may define a function and execute it 然后您可以定义一个函数并执行它

var d = new Function(Name.input.name, Name.input.param, Name.input.body);
d(otherdata);

this will omit the awful eval(...) stuff. 这将忽略可怕的eval(...)东西。 Caveat: it's still not a method of the given object. 注意:它仍然不是给定对象的方法。

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

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