Javascript 从对象的值中删除双引号
Javascript remove double quotes in from object's value
我正在 Java class 中生成一个 JavaScript 对象用于 javascript 结果如下所示:
var gridDefinition = {"width":"100%",
"height":700,
"sortable":true,
"columns"[{"datafield":"id","datatype":"string","width":300,"hidden":true,"text":"ID"},
{"datafield":"lastname","datatype":"string","cellsrenderer":"renderer_openEntry","width":300,"text":"Nachname"},
{"datafield":"firstname","datatype":"string","width":200,"text":"Vorname"},
{"datafield":"officePhoneNumber","datatype":"string","width":150,"text":"Telefon"},
{"datafield":"companyName","datatype":"string","width":300,"text":"Firma"},
{"datafield":"mailServer","datatype":"string","width":200,"text":"Mail-Server"},
{"datafield":"mailFile","datatype":"string","width":400,"text":"Mail-Datei"}]} ;
cellsrenderer 是一个回调函数名。如何删除 renderer_link 周围的双引号?结果行应如下所示:
{"datafield":"lastname","datatype":"string","cellsrenderer":renderer_openEntry,"width":300,"text":"Nachname"},
如何 "remove the quotes" 是个错误的问题。目前代码为 运行,没有可以删除的引号。
您需要的是将名称映射到变量的映射,例如
var myFunctions = {
renderer_openEntry: renderer_openEntry,
// other functions
};
然后处理对象以更新所有 cellsrender
属性的值以引用地图中的值而不是字符串:
gridDefinition.columns.forEachfunction(column) {
if (column.cellsrenderer) {
column.cellsrenderer = myFunctions[column.cellsrenderer];
}
});
我正在 Java class 中生成一个 JavaScript 对象用于 javascript 结果如下所示:
var gridDefinition = {"width":"100%",
"height":700,
"sortable":true,
"columns"[{"datafield":"id","datatype":"string","width":300,"hidden":true,"text":"ID"},
{"datafield":"lastname","datatype":"string","cellsrenderer":"renderer_openEntry","width":300,"text":"Nachname"},
{"datafield":"firstname","datatype":"string","width":200,"text":"Vorname"},
{"datafield":"officePhoneNumber","datatype":"string","width":150,"text":"Telefon"},
{"datafield":"companyName","datatype":"string","width":300,"text":"Firma"},
{"datafield":"mailServer","datatype":"string","width":200,"text":"Mail-Server"},
{"datafield":"mailFile","datatype":"string","width":400,"text":"Mail-Datei"}]} ;
cellsrenderer 是一个回调函数名。如何删除 renderer_link 周围的双引号?结果行应如下所示:
{"datafield":"lastname","datatype":"string","cellsrenderer":renderer_openEntry,"width":300,"text":"Nachname"},
如何 "remove the quotes" 是个错误的问题。目前代码为 运行,没有可以删除的引号。
您需要的是将名称映射到变量的映射,例如
var myFunctions = {
renderer_openEntry: renderer_openEntry,
// other functions
};
然后处理对象以更新所有 cellsrender
属性的值以引用地图中的值而不是字符串:
gridDefinition.columns.forEachfunction(column) {
if (column.cellsrenderer) {
column.cellsrenderer = myFunctions[column.cellsrenderer];
}
});