I search to solve problem with access to JS var(Object). I use Select2 lib on my Visualforce component wheare i get acsess to data from Salesforce objects( List of Emails and emails Id's) I use some code
<apex:component >
<apex:attribute name="fieldValue" description="This is the value for the component." type="String" required="true"/>
<apex:attribute name="optionList" description="This is the value for the component." type="Mywrapper[]" required="true"/>
<apex:includeScript value="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js" />
<apex:stylesheet value="{!URLFOR($Resource.Dropdown, 'dropdown/select2.css')}" />
<apex:includeScript value="{!URLFOR($Resource.Dropdown, 'dropdown/select2.js')}" />
<!-- Dropdown -->
<select id='{!fieldValue+"selUser"}' style='width: 200px;'>
<apex:repeat value="{!optionList}" var="option">
<option value="{!option.value}">{!option.label}</option>
</apex:repeat>
</select>
<input type='button' value='Save' id="{!fieldValue}but_read"/>
<br/>
<div id='{"result"}'></div>
<script>
var username;
var userid;
$j = jQuery.noConflict();
$j(document).ready(function(){
// Initialize select2
$j("#{!fieldValue}selUser").select2();
$j('#{!fieldValue}but_read').click(function(){
username = $j('#{!fieldValue}selUser option:selected').text();
userid = $j('#{!fieldValue}selUser').val();
var myobj = {
value: userid,
label: username
};
console.log(username+' '+userid);
console.log(myobj);
$j('#{!fieldValue}result').html("id : " + userid + ", name : " + username);
});
});
</script>
</apex:component>
I need some method for push "myobj" to Apex Class i get records but dont know how to push my change from dropdown picklist to Controller class. Maybe have some method with use JSON Deserialize for new result object?
myObj
data?@RemoteAction
and then call it this way developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/…