我正在尝试从对象数组中计算所选项目的数量。我在sonarqube中面临预期分配或函数调用问题。需要帮助解决此问题。
const dataList = [
{label: "test1", value: "test1", checked: true},
{label: "test2", value: "test2", checked: false},
{label: "test3", value: "test3", checked: true}];
const getSelectedCount2 = (dataList) => {
let selectedItemCount = 0;
dataList.forEach(item => item.checked ? selectedItemCount = selectedItemCount + 1 : "" );
return selectedItemCount;
}
有问题的线路是 dataList.forEach(item => item.checked ? selectedItemCount = selectedItemCount + 1 : "" );
暂无答案!
目前还没有任何答案,快来回答吧!