저는 모든 항목에 대해 JSONP 배열에서 네 개의 속성을 새로운 배열로 전송하려고하는 초보 프로그래머입니다.
1가 어떻게의 수에 따라 개체를 추가 할
bigarray = [{title:"xbox", url:"www.web.com", pic:"www.pic.com/w.png",price:"100"}, {title:"ps4", url:"www.web.com", pic:"www.pic.com/p.png",price:"110"}]
질문 :
$.ajax({
url: etsyURL,
dataType: 'jsonp',
success: function(data) {
if (data.ok) {
var a = (data.results);
//create a parent array to store all objects
var bigarray = [];
$.each(a, function(i, item) {
//assign values from response to variables
var atitle = item.title;
var aurl = item.url;
var aimg = item.Images[0].url_75x75;
var aprice = item.price;
//create an object
var object = {
title: atitle,
url: aurl,
img: aimg,
price: aprice
};
//add the object into big array for every each item, unsure
})
}
}
});
내 최종 목표는 다음과 같은 객체의 모든 항목을 모두 얻을 수 bigarray
를 얻는 것입니다 배열의 항목?
2. 다른 방법도 환영합니다. $ .even이 for 루프로 바뀌어도 답을 받아 들일 것입니다.
다음과 같이 코드를 수정할 수 있습니다'[] = 객체를 bigarray,' – pixelarbeit
경우'data.results을 ''$ .each()'-> ['Array.prototype.map()'] (https://developer.mozilla.org/en-US/docs/Web/JavaScript/)가 필요없는 배열입니다./global_Objects/Array/map), 그렇지 않으면 ['$ .map()'] (https://api.jquery.com/jquery.map/) (+ ['.get()'] (https : /api.jquery.com/get/)) – Andreas
푸시 기능을 사용하십시오. – Dimitri