Hi Pascal,
On Mon, Jul 27, 2015 at 11:42 AM, Pascal BASTIEN
<pbasnews-xwiki(a)yahoo.fr> wrote:
Hello,
My goal is to send array json variable from velocity to javacript or more precisely I
want loop over all objects of same Class of a page and put them in a json array
(
http://platform.xwiki.org/xwiki/bin/view/DevGuide/APIGuide#HAccessobjectsfr…)
But I didn't manage to edit an velocity array variable (add an entries or modify one)
AND
With velocity I declare my array like this:
#set ($MyArray={
'Index1':{'Field1':'value1','field2':'value2'},
'Index3':{'Field1':'A value','field2':'Another
value'}
})
This is not an array but a Map
http://docs.oracle.com/javase/7/docs/api/java/util/Map.html , which is
quite different. In any case, when you're not sure about the type of a
Velocity variable you should print $myVar.getClass().getName() to see
the real Java type and then you should check the Javadoc for that type
to see what methods you can call on the variable.
I'll let you discover how to modify a Java map object.
Hope this helps,
Marius
>
> How can I add an "Index2" entrie by example:
>
> 'Index2':{'Field1':'A new
value','field2':'Another new value'}"
>
> and/or can how can I modify a value ('Index 1'.field2' by example)?
>
> I tried to generate arraw velocity variable from a string like this,
>
> but unfortunaly generate a unique ... string :-(
>
> Here my code:
>
> {{velocity}}
>
#set ($MyArray={
'Index1':{'Field1':'value1','field2':'value2'},
'Index3':{'Field1':'A value','field2':'Another
value'}
})
> $jsontool.serialize($MyArray)
>
> Correct json arraw but I can NOT edit it :-(
>
{"Index1":{"Field1":"value1","field2":"value2"},"Index3":{"Field1":"A
value","field2":"Another value"}}
>
> ----
>
> #set ($MyArrayString="{")
> #set ($MyArrayString=$MyArrayString
+"'Index1':{'Field1':'value1','field2':'value2'},")
> #set ($MyArrayString=$MyArrayString +"'Index3':{'Field1':'A
value','field2':'Another value'}")
> #set ($MyArrayString=$MyArrayString +"}")
> $jsontool.serialize($MyArrayString)
>
> I can edit this json arraw but it as wrong json arraw because the ""
characters :-(
>
"{'Index1':{'Field1':'value1','field2':'value2'},'Index3':{'Field1':'A
value','field2':'Another value'}}"
>
> {{/velocity}}
>
>
>
> Thxs for any help
>
> Pascal b
> _______________________________________________
> users mailing list
> users(a)xwiki.org
>
http://lists.xwiki.org/mailman/listinfo/users