这就是我目前正在做的事情。我试着将我的json
中的值推入链接数组中,但输入数组后,值变为undefined
。什么是移动数据并使其仍然可用的更好方法?从使用此代码从我的JSON对象添加到我的列表数组中
var links = [];
$.ajax({
url: 'data.json',
dataType: 'json',
type: 'get',
cache: false,
success: function(data) {
$(data.emails).each(function(index, value) {
links.push(value);
});
}
});
//data.json contains:
{
"emails": [{
"source": "[email protected]",
"target": "[email protected]"
}]
}
结果是相同的。值输入数组,但是当您通过链接访问它们。(值的名称)返回“未定义”
$.each(data.emails, function(index, value) {
links.push(value);
console.log(links);
return value;
});
里面是什么 “数据”? – Sletheren
真正的问题是你在哪里返回,你在哪里检查'links'数组,为什么该数组有一个'target'属性? – adeneo
你在哪里检查'links'数组?请注意,AJAX请求是异步的。 –