我正在为每个附近的帐户显示标记,并且下面的锚标记应该在点击它时导航到相应的帐户。我已经使用了工作簿中的代码,但它既不适用于桌面也不适用于Salesforce1.I已检查用户的帖子报告说重定向发生在错误的页面。但是在我的案例页面中只刷新并保持在同一页面上。请帮助
try{
if(sforce.one){
accountNavUrl = 'javascript:sforce.one.navigateToSObject(\'' + account.Id + '\')';
}
} catch(err) {
console.log(err);
var dId=account.Id;
accountNavUrl= '\\' + account.Id;
}
console.log('-->'+accountNavUrl );
var content='<a href src="'+accountNavUrl +'" >'+account.Name+ '</a><br/>'+account.BillingStreet +'<br/>' + account.BillingCity +'<br/>' + account.BillingCountry;
以下是我的整个代码
<apex:page standardController="Account" extensions="AccountMapExt" sidebar="false" showHeader="false">
<!-- Begin Default Content REMOVE THIS -->
<apex:includeScript value="https://maps.googleapis.com/maps/api/js?sensor=false" />
<style>
html, body { height: 100%; }
.page-map, .ui-content, #map-canvas { width: 100%; height:100%; padding: 0; }
#map-canvas { height: min-height: 100%; }
</style>
<script>
var lat;
var lon;
function initialize(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(
function(position){
lat=position.coords.latitude;
lon=position.coords.longitude;
Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.AccountMapExt.getNearby}',lat, lon,
function(result, event){
if (event.status) {
console.log('->'+lat+' '+lon+' '+result);
createMap(lat, lon, result);
} else if (event.type ==='exception') {
//exception case code
} else {
}
},
{escape: true}
);
}
);
}
}
function createMap(lat,lon,accounts){
console.log('Calling map '+ lat+' '+lon);
var currentPosition = new google.maps.LatLng(lat,lon);
var mapDiv = document.getElementById('map-canvas');
var map = new google.maps.Map(mapDiv, {
center: currentPosition,
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var positionMarker = new google.maps.Marker({
map: map,
position: currentPosition,
icon: 'https://maps.google.com/mapfiles/ms/micons/green.png'
});
for(var i=0; i<accounts.length;i++){
account= accounts[i];
console.log(accounts[i]);
setupMarker();
}
function setupMarker(){
var accountNavUrl;
try{
if(sforce.one){
accountNavUrl = 'javascript:sforce.one.navigateToSObject(\'' + account.Id + '\')';
}
} catch(err) {
console.log(err);
var dId=account.Id;
accountNavUrl= '\\' + account.Id;
}
console.log('-->'+accountNavUrl );
var content='<a href src="'+accountNavUrl +'" >'+account.Name+ '</a><br/>'+account.BillingStreet +'<br/>' + account.BillingCity +'<br/>' + account.BillingCountry;
//Create the callout that will pop up on the marker
var infowindow = new google.maps.InfoWindow({content: content});
//Place the marker
var marker = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(account.BillingLatitude,account.BillingLongitude)}
);
google.maps.event.addListener(marker, 'click', function(){
infowindow.open(map, marker);
});
}
var mapBoundary = new google.maps.LatLngBounds();
mapBoundary.extend(currentPosition);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<body style="font-family: Arial; border: 0 none;">
<div id="map-canvas"></div>
</body>
<!-- End Default Content REMOVE THIS -->
</apex:page>
答案 0 :(得分:0)
下面的代码就行了!
var accountNavUrl;
try{
if(sforce.one){
accountNavUrl='<a href="javascript:sforce.one.navigateToSObject(\''+account.Id+'\');">';
}
} catch(err) {
console.log(err);
accountNavUrl='<a href="../' + account.Id + '" target="_parent">';
}
console.log('-->'+accountNavUrl );
var content=accountNavUrl+account.Name+ '</a><br/>'+account.BillingStreet +'<br/>' + account.BillingCity +'<br/>' + account.BillingCountry;