前端framework7 树
// 画无子的
function drawNoChildren(c, d) {
const childToNoChildHTML = global.app.templates.childToNoChildTemplate({
name: c.name,
id: c.id,
});
$$(`#${d.id}`).append(childToNoChildHTML);
$$(`#fj${c.id}`).on('click', showPic);
}
// 画有子的
function drawHasChildren(c, d) {
const childToChildHTML = global.app.templates.childToChildTemplate({
name: c.name,
id: c.id,
});
$$(`#${d.id}`).append(childToChildHTML);
}
function hasChildren(s) {
if (s.children.length === 0) {
return false;
}
return true;
}
// 遍历每一层的所有节点
function ergodicNodes(t) {
for (let a = 0; a < t.children.length; a += 1) { // 遍历下层节点
if (hasChildren(t.children[a]) === true) {
drawHasChildren(t.children[a], t); // 有孩子
ergodicNodes(t.children[a]);
} else {
drawNoChildren(t.children[a], t);
}
}
}
function successData(data0) {
$$('#rootLoop').html('');
const data = JSON.parse(data0);
if (data.length !== 0) {
for (let i = 0; i < data.length; i += 1) {
// 画根
const rootToChildHTML = global.app.templates.rootToChildTemplate({
name: data[i].name,
id: data[i].id,
});
$$('#rootLoop').append(rootToChildHTML);
ergodicNodes(data[i]);
}
}`在这里插入代码片`
//页面
<!DOCTYPE html>
<html>
<head>
{
{
> ../share/css}}
</head>
<body>
<!-- Views -->
<div class="views">
<!-- Your main view, should have "view-main" class -->
<div class="view view-main">
<div class="pages navbar-fixed">
<!-- Page, "data-page" contains page name -->
<div data-page="newKnowV3" class="page no-tabbar">
<!-- Page content -->
<div class="page-content pagecolor">
<form data-search-list=".list-block" data-search-in&#