js递归修改数据节点

function formatPrice(list,field,price) {
    list.forEach(item => {
        item[field] = price//实际处理的代码
        if (item.children) {
            if (item.children.length === 0) {
                delete item.children;
            } else if (item.children.length > 0) {
                formatPrice(item.children,field,price);
            }
        }
    });
    return data;
}

添加新评论