从API返回的地图数据

时间:2019-06-13 16:40:36

标签: javascript json

所以我试图使此功能起作用:

function get_data () {
let myObj = (JSON.parse(this.responseText));
return myObj;
}

var oReq = new XMLHttpRequest();
oReq.addEventListener("load", get_data);
oReq.open("GET", "http://localhost:3005/products?q=lc");
oReq.send();

let id_array = myObj.map(item = () => {return item.id});

,但id_array为空。当我键入:

console.log(myObj)

这是我的输出:

(10) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0: {id: "774944", general: {…}, brand: {…}, images: {…}}
1: {id: "774945", general: {…}, brand: {…}, images: {…}}
2: {id: "774946", general: {…}, brand: {…}, images: {…}}
3: {id: "782691", general: {…}, brand: {…}, images: {…}}
4: {id: "782485", general: {…}, brand: {…}, images: {…}}
5: {id: "782486", general: {…}, brand: {…}, images: {…}}
6: {id: "782487", general: {…}, brand: {…}, images: {…}}
7: {id: "782488", general: {…}, brand: {…}, images: {…}}
8: {id: "738471", general: {…}, brand: {…}, images: {…}}
9: {id: "765240", general: {…}, brand: {…}, images: {…}}
length: 10
__proto__: Array(0)

我需要将id值映射到id_array中,帮助您感激:)

0 个答案:

没有答案