function getLineItemList(quotationItemElements, checkedLineItemIds) {
var lineItemList = [];
quotationItemElements.children.forEach(function (quotElement, index) {
if(!parseBoolean(quotElement.isGroup)){
checkedLineItemIds.forEach(function (checkedId, index) {
if(quotElement.id == checkedId){
lineItemList.push(quotElement);
}
});
}else {
if(quotElement.children.length > 0){
getLineItemList(quotElement, checkedLineItemIds);
}
}
});
return lineItemList;
}
function parseBoolean(str) {
return /true/i.test(str);
}
我有不同程度的JavaScript
列表数据的同一层次空单,而不是循环的任何级别明确我使用递归调用(这是幸运的工作正常),但功能总是返回空列表。递归函数返回的JavaScript
提供上述功能 – dev
数据输入为例,来的jsfiddle让我们看到你的代码运行。 –
您可以在函数内部定义'lineItemList',这意味着每次调用该函数时都会从空数组开始。您需要将数组作为参数传递给函数,并且还需要'返回'getLineItemList'函数的结果。 – Titus