0

I have below string in my javascript variable which is returned from the controller as a wrapper value. I need to fetch the value of "Tasks" attribute from the javascript string variable on my vf page. Can anyone provide me any javascript method that can parse its value?

 var taskDetails = "DetailsList:[resources={}, tasks={a0e28000006wwRcAWQ=FormListItem:[id=a0e28000006wwRcAAI, name=Survey1, status=Published, surveyId=a0f28000005xYItAAM], a0e28000006wzy6AAA=FormListItem:[id=a0e28000006wzy6ADE, name=CLONE 1 Survey1, status=Published, surveyId=a0f28000005xYLsAAM], a0e28000006x0w6AAA=FormListItem:[id=a0e28000006x0w6DEA, name=CLONE 1 CLONE 1 Survey1, status=Closed, surveyId=a0f28000005xYNtAAM], a0e28000006xxpAAAQ=FormListItem:[id=a0e28000006xxpFGAQ, name=PPI Survey, status=Draft, surveyId=a0f2800000602NEAAY], a0e28000006xzMjAAI=FormListItem:[id=a0e28000006xzMDFAI, name=CLONE 1 Survey1, status=Published, surveyId=a0f28000005xYLsAAM], a0e28000007Lmd8AAC=FormListItem:[id=a0e28000007LmdWQAC, name=Draft Survey, status=Draft, surveyId=a0f28000006Iu2UAAS]}]"; 
1

Rather than try to parse that awkward to parse string, it makes more sense to output the data in a format that is easy to parse in JavaScript and that format is JSON.

So in the Apex code add a method somewhere:

public String getTaskDetailsJson() {
    // Its this easy to generate JSON in Apex
    return JSON.serialize(taskDetails);
}

and output that into a JavaScript variable in the Visualforce page (here in the simplest form):

var taskDetails = {!taskDetailsJson};

Then in your JavaScript you will be able to use simple JavaScript property or array references to directly access the data.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.