var x = {
defaultView : 'agendaWeek',
firstDay: 1, //0 = sunday 1= monday
weekends: true,
allDayText: 'gehele dag'
}
But now I need this object as text (literally) to embed in a function, to fire it inside a webclient (by using the WebClientUtils plugin)
I tried: x.toString() but that does not work.
How can I convert this object, to a textstring, which has to be literally, everything between the { }
Hope someone can point me in the right direction.
JSON.stringify(obj) and JSON.parse(str) are new to 6.1 because of the updated Rhino engine. We moved to 6.1 just for this as much as anything else (and ended up liking a ton of other 6.1 features) because in our CMS we do this stuff all the time.
If you insist in 6.0 or earlier, you can use plugins.serialize.toJSON(obj) – the trick is to know the issues with types and then the pattern to the “crap” (I agree) it produces when applying JSON.parse(str) to it client-side.
1- Properties will have an underscore at the beginning when parsed client-side:
// server
var x = {
defaultView : 'agendaWeek',
firstDay: 1, //0 = sunday 1= monday
weekends: "true", // I changed value to a string
allDayText: 'gehele dag'
}
return plugins.serialize.toJSON(x)
// web client
var x = JSON.parse(str)
console.log(x._defaultView) // "agendaWeek"
console.log(x._firstDay) // "1"
console.log(x._weekends) // "true"
console.log(x._allDayText) "gehele dag"
2- Change boolean value to strings before serializing…ie, true becomes “true”.
3- Change number values to strings before serializing. Do this if you need to make sure to get the correct rounding. Integers ok to leave as integers.
4- Change dates to some string equivalent before serializing.
After de-serializing on the client-side, you will need to convert strings back into appropriate types if you’re going to further use them as javascript objects (calculations and such). Handling dates this way is especially tedious.
Yes, Robert is right: the latest v2.0.x version of VelocityReports expose fromJSON and toJSON methods and this is working fine with any Servoy from 5.2 to 6.1 - haven’t tested lately but I suppose it would also work im 4.1.x…
ptalbot:
Yes, Robert is right: the latest v2.0.x version of VelocityReports expose fromJSON and toJSON methods and this is working fine with any Servoy from 5.2 to 6.1 - haven’t tested lately but I suppose it would also work im 4.1.x…
Cool. Would have helped a whole bunch of lot last year