我嘗試過這樣的事情<script charset="utf-8"> var request = new XMLHttpRequest(); // request.open("POST", "https://localhost:8443/control/jqxGeneralServicer?sname=JQGetListCustomerByCluster&deliveryClusterId=120120", false); request.open("POST", "https://localhost:8443/control/jqxGeneralServicer?sname=JQGetListCustomerByCluster&deliveryClusterId=${deliveryCluster.deliveryClusterId}", false); // ${deliveryCluster.deliveryClusterId} request.setRequestHeader('Content-Type', 'application/json'); request.send(null); var foo = request.responseText; var json = JSON.parse(foo); // console.log(json["results"][0]); var labels = new Array(); var locations = new Array(); for(i = 0; i < json["results"].length; i++){ labels.push(json["results"][i]["fullName"]); locacations["lng"] = json["results"][i]["longitude"]; locacations["lat"] = json["results"][i]["latitude"]; } // console.log(labels) ; function initMap() { const map = new google.maps.Map(document.getElementById("map"), { zoom: 16, center: {lat: 20.993514917846174, lng: 105.78660475957122}, }); // const labels = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; //const labels = [ // "C?a hàng Quang Anh", // "C?a hàng Quang Em", // "C?a hàng H?ng Th?nh", // "C?a hàng C?a hàng Thành H?ng"]; var locations = [ { lat: 20.9935851166474, lng: 105.78857910579417 }, { lat: 20.986910834987295, lng: 105.78535398147808 }, { lat: 20.990339683019226, lng: 105.7922698253056 }, { lat: 20.996770381033244, lng: 105.79321396285934 } }); });請指導(dǎo)我locations從json數(shù)據(jù)源設(shè)置 var 的值。
如何將對象的值設(shè)置為對象數(shù)組?
守候你守候我
2023-10-20 15:14:41