我想将元素从 $.each 循环更新到数组中,但它错误地将它们加载到数组中。它将所有用户放入一个元素中,将所有日期放入一个元素中,依此类推。代码如下:
var array = [{
user: "",
user_id: "",
date: "",
profile_img: "",
text: "",
contentString: "",
url: "",
location: ""
}];
$.getJSON("http://search.twitter.com/search.json?q=%23euronews&rpp=5&include_entities=true&result_type=mixed&callback=?",
function (data) {
$.each(data.results, function (i, item) {
var user = item.from_user;
var user_id = item.from_user_id;
var date = item.created_at;
var profile_img = item.profile_image_url;
var text = item.text;
var contentString = text;
var url = (item.entities.urls.length > 0 ? item.entities.urls[0].url : '');
console.log(i);
array.user=user;
array.user_id=user_id;
array.date=date;
array.profile_img=profile_img;
array.text=text;
array.contentString=contentString;
array.url=url;
});
console.log(array);
});
我该怎么做才能解决这个问题?