从外部文件获取Javascript值
Javascript文件中位置从外部文件获取Javascript值,javascript,Javascript,Javascript文件中位置var位置的详细信息。我想在外部集成JS文件中这些位置的详细信息 .... function mainMap() { function locationData(locationURL, locationPrice, locationPriceDetails, locationImg, locationTitle, locationAddress) { return ('<a href="' + locationURL
var位置的详细信息。我想在外部集成JS文件中这些位置的详细信息
....
function mainMap() {
function locationData(locationURL, locationPrice, locationPriceDetails, locationImg, locationTitle, locationAddress) {
return ('<a href="' + locationURL + '" class="listing-img-container"><div class="infoBox-close"><i class="fa fa-times"></i></div><div class="listing-img-content"><span class="listing-price">' + locationPrice + '<i>' + locationPriceDetails + '</i></span></div><img src="' + locationImg + '" alt=""></a><div class="listing-content"><div class="listing-title"><h4><a href="#">' + locationTitle + '</a></h4><p>' + locationAddress + '</p></div></div>')
}
var locations = [
[locationData('link1', '$275,000', '$520 / sq ft', 'img.jpg', 'Eagle Apartmets', "9364 School St. Lynchburg, NY"), 40.7427837, -73.11445617675781, 1, markerIcon],
[locationData('link2', '$135,000', '$120 / sq ft', 'img.jpg', 'Stack Apartmets', "1234 School St. Lynchburg, NY"), 40.7317837, -73.11435617675781, 1, markerIcon],
,];
var mapZoomAttr = $('#map').attr('data-map-zoom');
var mapScrollAttr = $('#map').attr('data-map-scroll');
if (typeof mapZoomAttr !== typeof undefined && mapZoomAttr !== false) {
var zoomLevel = parseInt(mapZoomAttr);
} else {
var zoomLevel = 5;
}
....
结果:
[...]
echo "<script>var locationDetails = [[locationData('link1','$275,000','$520 / sq ft', 'img.jpg', 'Eagle Apartmets', "9364 School St.Lynchburg, NY"), 40.7427837, -73.11445617675781, 1, markerIcon], [locationData('link2', '$135,000', '$120 / sq ft', 'img.jpg', 'StackApartmets', "1234 School St. Lynchburg, NY"), 40.7317837, -73.11435617675781,1, markerIcon],];
[...]
var locations = locationDetails;
不工作
为什么不起作用?我做错了什么?
多谢各位
您可以在MDN上阅读
出口示例:
export const one = 1
// or to export multiple
const two = 2
const three = 3
export {
two,
three
}
导入示例:
import { one, two, three } from './export' // path of export
console.log(one, two, three)
我对这个问题不是100%清楚。那么您有一个.js文件要从中加载值和变量?您需要export const myVar='VARRR'
和import{myVar}from./myfile'
才能使用myVar
。@您明白了吗,请给我看一下代码上的示例?