Copy link to clipboard
Copied
I am not abel to send a array between JS and JSX in my CEP panel using JSON.stringify. The JSX function doeasnt get called at all. The alert below doesn't come through.
If i don't use JSON.stringify the array gets send not as an array but just comma seperated vaules. The array structure is lost.
My JS function
function generateList() {
var ruleData = [["filename","doesntcontain","kkk"], ["clipname","doesntcontain","kkk"]]
var andor = "and";
if (document.getElementById("andor-select2").checked) {
andor = "or"
}
if (ruleData === "Error") {
return;
}
var ruleDataStr = JSON.stringify(ruleData)
console.log(ruleDataStr)
var csInterface = new CSInterface();
csInterface.evalScript('searchTimeline("' + ruleDataStr + '", "' + andor + '")')
}My JSX function
function searchTimeline (ruleData, andor) {
alert("here")}
Any suggestions?
At first glance, I suspect the double-then-single quotes before and after 'ruleDataStr', and 'andor'.
It's not JSON-related, but have a look at this JavaScript function in PProPanel; it builds up a complicated evalScript() command.
Youre right, the double quotes were the issue! I escaped the quotes in the string and now its working.
var ruleDataStr = JSON.stringify(ruleData)
var ruleDataEscaped = ruleDataStr.replace(/"/g, '\\"'); // Escape double quotes
Copy link to clipboard
Copied
At first glance, I suspect the double-then-single quotes before and after 'ruleDataStr', and 'andor'.
It's not JSON-related, but have a look at this JavaScript function in PProPanel; it builds up a complicated evalScript() command.
Copy link to clipboard
Copied
Youre right, the double quotes were the issue! I escaped the quotes in the string and now its working.
var ruleDataStr = JSON.stringify(ruleData)
var ruleDataEscaped = ruleDataStr.replace(/"/g, '\\"'); // Escape double quotes
Find more inspiration, events, and resources on the new Adobe Community
Explore Now