使用数组筛选CSV的行以在CSV中显示arrayItem:1



我构建了以下函数,当用户按下按钮时,字符串会附加到数组中(按钮也会变为红色(。我的脚本中有d3和JQ(尚未使用(:

// Create button click array
var clickedBusinesses = [];
function toggle(business) {
clickedBusinesses[business] = !clickedBusinesses[business];
};
function getClickedBusinesses() {
return Object.keys(clickedBusinesses).filter(key => clickedBusinesses[key]);
};

// Update array and change button colour to reflect selection
function toggleClickedBuz( bizStr , id ) {
if(clickedBusinesses.includes(bizStr)){
// removing duplicate element from that array, dependant on button pressed
clickedBusinesses = clickedBusinesses.filter( cb => cb !== bizStr );
document.getElementById( id ).style.backgroundColor='white';
}else{
// else push it to the array
clickedBusinesses.push(bizStr)
document.getElementById( id ).style.backgroundColor='red';
}
console.log(clickedBusinesses)
var arrayLength = clickedBusinesses.length;
for (var i = 0; i < arrayLength; i++) {
console.log(clickedBusinesses[i]);
// Do something
}
}

我正试图使用此数组筛选CSV中的列,以仅显示值"1.0">

const data = d3.csv("./binary.csv").then(function(data){
console.log(data);
});

这就是控制台窗口中每行(6k(的样子:

{is_active: "1", "Bx": "1", "By": "1", "Bz": "0", count: "5,133,151"}

我正在努力创建一个逻辑,该逻辑遍历数据,并且只返回特定键(Bx、By、Bz-取决于选择(具有指定值(1(的值。

感谢

const clickedBusinesses = [
];
const business = [
{ is_active: "1", Bx: "1", By: "1", Bz: "0", count: "5,133,151" },
{ is_active: "0", Bx: "1", By: "1", Bz: "0", count: "5,1121,151" },
{ is_active: "0", Bx: "1", By: "1", Bz: "0", count: "5,1212,151" },
]
// Update array and change button colour to reflect selection
function toggleClickedBuz(index, id) {
var data = business[index];
if (data) {
document.getElementById(id).style.backgroundColor = "white";
} else {
clickedBusinesses.push(index);
document.getElementById(id).style.backgroundColor = "red";
}
for (let item of clickedBusinesses ) {
console.log(item);
// Do something
}
}

最新更新