Passing Apex inner class List to JavaScript
Declare this in the script
In Controller
In VF section of the page let JSList refresh when ever innerClassObjList updates.
- var JSList = new Array();
- function JSObj() {
- this.recId= '';
- this.Name= '';
- }
In Controller
- public List<innerClassObj> innerClassObjList {get;set;}
- public class innerClassObj{
- public String InnerId {get; private set;}
- public String InnerName {get; private set;}
- }
In VF section of the page let JSList refresh when ever innerClassObjList updates.
- <apex:repeat value="{!innerClassObjList}" var="innObj">
- <script>
- var JSListObj = new JSObj();
- JSListObj.recId = '{!innObj.InnerId}';
- JSListObj.Name= '{!innObj.InnerName}';
- JSList.push(JSListObj);
- </script>
- </apex:repeat>
Or the other and more suitable solution for many perspectives could be passing the inner class list by Serializing it with JSON.serialize()
Comments
Post a Comment