void DumpTreeNG(const RefPtr<NG::FrameNode>& parent, int32_t depth, NodeId nodeID, int32_t pageId) { auto node = GetInspectorById(parent, nodeID); if (!node) { return; } if (!node->IsActive()) { return; } NG::RectF rect = node->GetTransformRectRelativeToWindow(); DumpLog::GetInstance().AddDesc("ID: " + std::to_string(node->GetAccessibilityId())); DumpLog::GetInstance().AddDesc("compid: " + node->GetInspectorId().value_or("")); std::vector<int32_t> children; for (const auto& item : node->GetChildren()) { GetFrameNodeChildren(item, children, pageId); } DumpLog::GetInstance().Print(depth, node->GetTag(), children.size()); for (auto nodeId : children) { DumpTreeNG(node, depth + 1, nodeId, pageId); } }改写此段代码,将父节点和子节点打印出的信息全部放在一个vector<ComponentInfo> com1容器中,ComponentInfo是一个struct其中的成员变量是 ComponentInfo{ std::string ID; std::string text; std::vector<ComponentInfo> children;}
时间: 2024-04-03 22:33:04 浏览: 128
:desktop_computer:Node.js的简单而功能强大的服务器-Node.js开发
void DumpTreeNG(const RefPtr<NG::FrameNode>& parent, int32_t depth, NodeId nodeID, int32_t pageId, std::vector<ComponentInfo>& com1) {
auto node = GetInspectorById(parent, nodeID);
if (!node) {
return;
}
if (!node->IsActive()) {
return;
}
NG::RectF rect = node->GetTransformRectRelativeToWindow();
ComponentInfo info;
info.ID = std::to_string(node->GetAccessibilityId());
info.text = node->GetTag();
info.children = std::vector<ComponentInfo>();
for (const auto& item : node->GetChildren()) {
std::vector<int32_t> children;
GetFrameNodeChildren(item, children, pageId);
for (auto nodeId : children) {
ComponentInfo childInfo;
DumpTreeNG(item, depth + 1, nodeId, pageId, childInfo.children);
info.children.push_back(childInfo);
}
}
com1.push_back(info);
}
阅读全文