ajax调用数据
$.getJSON("data/yinzhou.json", "", function (res, status) { var data = res.features; // console.log(data); //分组渲染; if (status == "success") { arrChunk(data, 1); } else { console.log("Cann't GET Data.") } })
封装分组函数
function arrChunk(data, chunk) { var result = []; //数组分组数量; var chunk = chunk; //执行数组分组; for (var i = 0, j = data.length; i < j; i += chunk) { result.push(data.slice(i, i + chunk)); } //分组后的数据进行渲染; for (var k = 0; k < result.length; k++) { var j = 0; setTimeout(function () { console.log(result[j++][0].properties.name); }, k * 500) } }
Done !