一、思路
我们已经明确的获得了,整个的目录关系,由于每一个child的是不停的嵌套,导致我们不知道什么时候是头,所以这里使用递归
-
我们可以确定的是所用的主根目录,因为主目录是所有的头
def menu_tree(self):
response = ' '
tpl = '''
<div class="'itme %s">
<div class="'title">%s</div>
<div class="content">%s</div>
</div>
'''
for row in self.menu_data_list():
if not row['status']:
continue
active = ''
if row['opend']:
active = 'active'
if 'url' in row:
response += '<a class=%s href="%s">%s</a>' % (active, row['url'], row['caption'])
else:
title = row['caption']
content = self.menu_content(row['child'])
response += tpl % (active, title, content)
return response
-
我们不知道内容目录什么时候到头所以递归内容目录
def menu_content(self,child_list):
response = ' '
tpl = '''
<div class="'itme %s">
<div class="'title">%s</div>
<div class="content">%s</div>
</div>
'''
for row in child_list:
if not row['status']:
continue
active = ''
if row['opend']:
active = 'active'
if 'url' in row:
response += '<a class=%s href="%s">%s</a>' % (active, row['url'], row['caption'])
else:
title = row['caption']
content = self.menu_content(row['child'])
response += tpl % (active, title, content)
return response