我遇到了nodejs的问题。我试着用node-xlsx库读取一个xml文件。
libreary正确读取文件,并在数组中添加信息。问题是当我尝试用这个数组挂载其他数组时。
代码:
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].checked) on.push(checkboxes[i].value);
<div id='filters' class='ui-select'>
<div><input type='checkbox' checked=checked class='filter'
name='filter' id='fast-food' value='fast-food'/><label for='fast-food'>fast-food</label></div>
<div><input type='checkbox' checked=checked class='filter'
name='filter' id='bicycle' value='bicycle'/><label for='bicycle'>bicycle</label></div>
<div><input type='checkbox' checked=checked class='filter'
name='filter' id='bar' value='bar'/><label for='bar'>bar</label></div>
</div>
<div id='map'></div>
<script>
L.mapbox.accessToken = 'pk.eyJ1IjoiaXNrYW5kYXJibHVlIiwiYSI6ImNpazE3MTJldjAzYzZ1Nm0wdXZnMGU2MGMifQ.i3E1_b9QXJS8xXuPy3OTcg';
var map = L.mapbox.map('map', 'mapbox.dc-markers');
var filters = document.getElementById('filters');
var checkboxes = document.getElementsByClassName('filter');
function change() {
// Find all checkboxes that are checked and build a list of their values
var on = [];
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].checked) on.push(checkboxes[i].value);
}
// The filter function takes a GeoJSON feature object
// and returns true to show it or false to hide it.
map.featureLayer.setFilter(function (f) {
// check each marker's symbol to see if its value is in the list
// of symbols that should be on, stored in the 'on' array
return on.indexOf(f.properties['marker-symbol']) !== -1;
});
return false;
}
// When the form is touched, re-filter markers
filters.onchange = change;
// Initially filter the markers
change();
</script>
如果我看到console.log(连接),则会正确创建任何对象。我在数组中添加此对象以返回所有信息。
但是如果我读取第二个控制台日志,console.log(连接)以查看我返回的内容,则数组中的所有对象都是相同的。都像for循环的最后一个值..