After one fastidious debuging day ;-)) , here some snippet to edit map with 
velocity with put and/or velocity variable (with space character):

#set ($MyArray1={})
* $jsontool.serialize($MyArray1)
#set ($indexNiv1='Index 2')
##set ($discard=$MyArray1.put('Index2',{}))
#set ($MyArray1[$indexNiv1]={})
* $jsontool.serialize($MyArray1)
##set ($discard=$MyArray2.put('Index2',{'Field1':'Addon value'}))
#set ($field1='Field 1')
##set ($discard=$MyArray1.put($indexNiv1,{$field1:'Addon value'}))
#set ($MyArray1[$indexNiv1][$field1]='Addon value')
* $jsontool.serialize($MyArray1)
#set ($field2="Field 2")
##set ($discard=$MyArray1[$indexNiv1].put($field2,'Another value'))
#set ($MyArray1[$indexNiv1][$field2]='Another value')
* $jsontool.serialize($MyArray1)
#set ($discard=$MyArray1.put('Index 2',{'Field1':'Addon value','field 
2':'Another addon value'}))
* Values in one shot:  $jsontool.serialize($MyArray1)
$MyArray1.keySet()


--- En date de : Lun 27.7.15, Pascal BASTIEN <[email protected]> a écrit :

> De: Pascal BASTIEN <[email protected]>
> Objet: Re: [xwiki-users] Need help with velocity+json
> À: "XWiki Users" <[email protected]>, "Marius Dumitru Florea" 
> <[email protected]>
> Date: Lundi 27 juillet 2015, 15h48
> By the way, are there a
> "xwiki tricks" to pass a variable from velocity to
> javascript ?
> 
> Anyways, this
> way working well (replace MyArray by MyMap ;-) ) :
> 
> {{velocity}}
> {{html}}
> #set ($MyArray={
>  
> 'Index1':{'Field1':'value1','field2':'value2'},
>   'Index3':{'Field1':'A
> value','field2':'Another value'}
> })
>  <script
> type="text/javascript">
>    var
> MaVariable=$jsontool.serialize($MyArray);
> 
> </script>
> {{/html}}
> {{/velocity}}
> 
> And in my XWiki.JavaScriptExtension object:
> 
> function change_value(bouton,
> idTarget) {
>    
> require(['jquery'], function ($) {
>     // xxxxx
>     var obj
> = MaVariable;
>    
> alert(obj["Index2"]["field2"]);
> 
>     });
> };
> 
> --------------------------------------------
> En date de : Lun 27.7.15, Pascal BASTIEN
> <[email protected]>
> a écrit :
> 
>  Objet: Re:
> [xwiki-users] Need help with velocity+json
> 
> À: "XWiki Users" <[email protected]>,
> "Marius Dumitru Florea" <[email protected]>
> 
> Date: Lundi 27 juillet 2015, 12h01
>  
>  Thxs a lot:
>  "put"
> is my new friend :-)
>  
>  Here
> the answer:
>  #set
> 
> ($MyArray={
>   
> 
> 'Index1':{'Field1':'value1','field2':'value2'},
>   
> 'Index3':{'Field1':'A
> 
> value','field2':'Another value'}
>  })
> 
> $MyArray.getClass().getName()
>  *
>  Original map
> 
> $jsontool.serialize($MyArray)
>  *
>  I Modify the 'Index3' entrie:
>  #set
> 
> ($discard=$MyArray.put('Index3',{'Field1':'A
>  modified
> value','field2':'Another modified
>  value'}))
> 
> $jsontool.serialize($MyArray)
>  *
>  I add the 'Index2' entrie:
>  #set
> 
> ($discard=$MyArray.put('Index2',{'Field1':'Addon
>  value','field2':'Another
> addon
>  value'}))
> 
> $jsontool.serialize($MyArray)
>  
> _______________________________________________
> users mailing list
> [email protected]
> http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________
users mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to