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 <pbasnews-xw...@yahoo.fr> a écrit :

 Objet: Re: [xwiki-users] Need help with velocity+json
 À: "XWiki Users" <users@xwiki.org>, "Marius Dumitru Florea" 
<mariusdumitru.flo...@xwiki.com>
 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
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to