仅获取列表中的ID

时间:2012-08-22 10:09:57

标签: javascript salesforce apex-code visualforce

我想找到mapquest上2个位置之间的距离。我通过硬编码JavaScript中的值来实现它。现在我试图从2个帐户中获取值,并使用纬度和经度值来查找距离。我已经创建了一个控制器,在控制器中我有一个记录列表Longitude_ c和Latitude _c,我已将值传递给我循环并添加到Array中的JavaScript。直到它工作正常但我的问题是我只从数组中获取Id而不是Latitude_ c和Longitude _c字段的值。

    <apex:page id="pageId" standardController="Account"       extensions="checkDistanceController">
  <script src="http://www.mapquestapi.com/sdk/js/v7.0.s/mqa.toolkit.js?     key=Fmjtd%7Cluua250221%2C2a%3Do5-9620ua"></script>

   <script type="text/javascript">


   function checkDistance(distance1) {
        alert('{!listzise}');
        var listsizeJs = {!listzise};
        alert(listsizeJs);
        var AcLon=new Array();
         var AcLat=new Array();
         var JsAcLst=new Array();

        var idx = 0;
         <apex:repeat value="{!acLst}" var="ele">
             JsAcLst[idx++]="{!ele}";
        </apex:repeat>



        for(var i=0; i<listsizeJs ; i++){
            alert("in for loop" + i);
            var llone={lat:40.730318, lng:-73.990603};   
            var llTow={lat:34.043897, lng:-118.209373};
            alert('Accunt List Apex : {!acLst}');
            alert('Accunt List JsLst:'+ JsAcLst[i]);

         }
             var distance = MQA.Util.arcDistance(llone, llTow, 'm');
            var distance1 = MQA.Util.distanceBetween(llone, llTow, 'm');
           alert(" Account Distance ........ " + Act_Distance);

           document.getElementById("pageId:formId:theBlock:pageBlockSectionid1:outputId1").innerHTML=distance;
           document.getElementById("pageId:formId:theBlock:pageBlockSectionid1:outputId2").innerH    TML=distance1;


 };



    </script>

     <apex:form id="formId">



            <apex:pageBlock title="Check Distance Between Vendors" mode="edit"  id="theBlock" >
                  <apex:pageBlockButtons location="both"> 
                          <apex:commandButton value="Find Distance" action="{!chkDistance}" onclick="checkDistance()" reRender="distanceID"/>

                  </apex:pageBlockButtons>
                  <apex:pageBlockSection columns="2" id="pageBlockSectionid1">

                          <apex:outputText id="outputId1" label="Arc `Distance :"></apex:outputText>
                           <apex:outputText id="outputId2" label="Distance Between :"></apex:outputText>

                 </apex:pageBlockSection>
            </apex:pageBlock>

      </apex:form>
</apex:page>

控制器

    public with sharing class checkDistanceController 
{

    public String Account { get; set; }



     public Account theAccount{get;set;}
     public Event_Equipment__c theEventEquipment{get;set;}
     public string Longitude {get;set;}
      public string Latitude {get;set;}
      public list<Account> acLst {get; set;}
     public decimal listzise{get;set;}
      list<Account> acLst = new list<Account>();

     public checkDistanceController(ApexPages.StandardController controller) {
         acLst = [Select Latitude__c, Longitude__c from Account where Longitude__c != null and Latitude__c != null limit 2];
        listzise = acLst.size();
   }
     }

任何人都可以帮我解决这个问题。

由于 ANU

1 个答案:

答案 0 :(得分:0)

你想将经度和纬度作为一个字符串放在数组中吗?试试这个:

<apex:repeat value="{!acLst}" var="ele">
    JsAcLst[idx++]="{!ele.Latitude__c},{!ele.Longitude__c}";
</apex:repeat>