Tell me more ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.
Calculator__c objCalculator  = [Select id, name, (select id,
fee_amount__c, cost_Amount__c, Type__c, from
Non_Labor_Cost_Details__r) From Calculator__c p where id =: PId];

When I try to use this object in Javascript like this:

{!objPricingCalculator.Non_Labor_Cost_Details__r}

It returns only list of Ids (comma separated). It's not returning fee_amount__c, cost_Amount__c and Type__c values.

Is there any way through which I can also extract fee_amount__c, cost_Amount__c and Type__c along with Id.

I don't want to use Javascript Remoting as I will have to change code flow for this.

share|improve this question
 
Thanks @Matthew for editing the question. –  Pramod Kumar Jul 29 at 13:39
 
You're welcome :) –  Matthew Keefe Jul 29 at 13:43

1 Answer

up vote 2 down vote accepted

//Apex class

 public class sample{

 public Account gethello(){

      Account acc=[Select Id,(Select id,Name from Contacts) from Account where Id =acc.id];
     return acc;

   }
}

Visualforce code with Javascript

<apex:page controller="sample">

<script>

<apex:repeat var="a" value="{!hello.Contacts}">
   alert('hello'+'{!a.Name}');
 </apex:repeat>

 </script>

 </apex:page>

This is the starting point.Now you can declare your own function in javascript something like this in script

function Contact(){
      /* Note the field names are case-sensitive! */
      this.Id = null; /* set a value here if you need to update or delete */
      this.Name = null;
  }

After this you can use push function of javascript to form an object array using some samples from below URL.

http://www.w3schools.com/jsref/jsref_push.asp

share|improve this answer
 
Thanks a lot @Mohith. You made my day. Can we use any Visualforce component in javascript or can only use components that are used to iterate things? –  Pramod Kumar Jul 29 at 14:06
 
I usually use apex repeat only !Never tried others in script as it makes no sense but repeat works for sure as i have seen –  Mohith Kumar Jul 29 at 14:22
1  
You "can" use any element you want inside JavaScript, but the question is if it would make sense. For example, you could use <apex:commandButton> inside a string to generate HTML code that you could put into an innerHTML value later. Generally you won't want/need to do this, but apex:repeat happens to be incredibly useful for building lists of data. –  sfdcfox Jul 30 at 1:30
 
Thanks a lot @sfdcfox. –  Pramod Kumar Jul 30 at 5:23
 
I had to place the script tags inside the repeat but it worked. Thanks. –  wisemanIV Nov 4 at 19:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.