PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → Webdev 22 pass paramter to JS function
Webdev 22 pass paramter to JS function
Iniciado por guest, 06,ene. 2018 23:53 - 2 respuestas
Publicado el 06,enero 2018 - 23:53
Hello All,

I need to pass data to a JS function that is formatted as JSON. if I use a button to create the data and call a local browser JS function and pass the data as a string.

[ { "title":"Jim Longer", "id":"1234", "start":"2018-01-12T10:30:00", "end":"2018-01-12T12:30:00" }, { "title":"Steve Smith", "id":"14", "start":"2018-03-12T10:30:00", "end":"2018-03-12T12:30:00" } ]
The function does not work.
If I hard code it in the JS function it works.
var eventData = [{"title":"Joe Moe","id":"123","start":"2018-01-12T10:30:00","end":"2018-01-12T12:30:00"},{"title":"Bill Smith","id":"456","start":"2018-01-14T10:30:00","end":"2018-01-14T12:30:00"}]
code of Function:
function lbp_FilterCalendar(sData){ $('#A1').fullCalendar({ header: { center: 'week,twoweek,threeweek,fourweek' // buttons for switching between views }, defaultView: 'week', editable: true, eventLimit: true, // allow "more" link when too many events events: sData, views: { week: { type: 'basic', /* 'basicWeek' ?? */ duration: { weeks: 1 }, buttonText: '1 Week' }, twoweek: { type: 'basic', duration: { weeks: 2 }, buttonText: '2 Week' }, threeweek: { type: 'basic', duration: { weeks: 3 }, buttonText: '3 Week' }, fourweek: { type: 'basic', duration: { weeks: 4 }, buttonText: '4 Week' } } }); }
Thanks DW
Publicado el 07,enero 2018 - 12:55
Hi Dennis

from your description, I'm guessing that your wlanguage code is incorrect, but as it's the ONE thing your are NOT showing us, I don't see how anybody could help.

Best regards
Publicado el 07,enero 2018 - 13:44
Hello Fabrice,

I solved it.

The function needed the data to be a JSON object not a sting. Windev (Or I for that matter) was sending it as a string.

To fix it I used code below in the js function and it worked.
var json = JSON.parse(sData)

this is the code to build the data:

stJason is Structure title is string id is string start is string 'end' is string END arrLoad is array of stJason nRow is int nRow = ArrayAdd(arrLoad) arrLoad[nRow].title = "Jim Longer" arrLoad[nRow].id = "1234" arrLoad[nRow].start = "2018-01-12T10:30:00" arrLoad[nRow].end = "2018-01-12T12:30:00" nRow = ArrayAdd(arrLoad) arrLoad[nRow].title = "Steve Meet" arrLoad[nRow].id = "14" arrLoad[nRow].start = "2018-01-13T10:30:00" arrLoad[nRow].end = "2018-01-13T12:30:00" bufJason is Buffer Serialize(arrLoad,bufJason,psdJSON)
DW