Skip to main content
Participant
April 5, 2023
Answered

Can't send array from CEP panel to JSX

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?

This topic is closed to new replies. Start a new post to keep the conversation going.
Jannik5C59Correct answer
Participant
April 5, 2023

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

2 replies

bbb_999
Community Manager
Community Manager
April 5, 2023

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. 

Translate
Jannik5C59AuthorCorrect answer
Participant
April 5, 2023

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
Translate