그래서 jQuery를 사용 하여이 코드가 있습니다.
require("./locations.js");
$( document ).ready(function() {
console.log("Adding locations..");
$.each(locations, function(key,loc) {
if (loc.popular == 1) $(".popular-list").append("<a href='#'><li class='loc'>Hello</li></a>");
});
$.ajax({
url : "changelog.txt",
dataType: "text",
success : function (data) {
$(".the-log").html(data);
}
});
});
다음을 locations.js
포함합니다.
var locations = [
{ name: "Varrocka", lng: 22.5, lat: -15.52249812756166, popular: 1 },
{ name: 'Lumbridge', lng: -43.644025847699496, lat: 25.9661865234375, popular: 1 },
{ name: "Monastery", lng: -4.0924072265625, lat: -5.714379819235291 },
{ name: "Edgeville", lng: 2.4884033203125, lat: -6.0094592380595495, popular: 1 },
{ name: "Varrock Palace", lng: 22.412109375, lat: -6.882800241767556 },
{ name: "Digsite", lng: 46.043701171875, lat: -17.266727823520508 }
];
그러나 $.each
위의 첫 번째 코드 블록에 다음과 같은 오류가 발생합니다.
Uncaught ReferenceError: locations is not defined
자, 방금 초기화했다고 생각했는데 ... webpack.config.js
module.exports = {
entry: "./src/js/main.js",
output: {
path: __dirname,
filename: "bundle.js"
}
};
그리고 bundle.js
와 locations.js
가에 저장되어있는 같은 디렉터리에있는 js/bundle.js
및 js/locations.js
respetively.
내가 무엇을 잘못하고 있지?
당신은 뭔가 내 보내야 locations.js
등을
module.exports = [
{ name: "Varrocka", lng: 22.5, lat: -15.52249812756166, popular: 1 },
...
];
그런 다음
var locations = require("./locations.js");;
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다