亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將對象的值設置為對象數組?

如何將對象的值設置為對象數組?

守候你守候我 2023-10-20 15:14:41
我嘗試過這樣的事情<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 }                });            });請指導我locations從json數據源設置 var 的值。
查看完整描述

1 回答

?
倚天杖

TA貢獻1828條經驗 獲得超3個贊

只需推送一個對象即可:

locations.push({lng: json['results'][i]['longitude'], lat: json['results'][i]['latitude']});

請注意,您不應該使用同步 http 請求。


查看完整回答
反對 回復 2023-10-20
  • 1 回答
  • 0 關注
  • 107 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號