首先需要创建一个树结构,可以看我这篇文章来实现.
https://blog.csdn.net/u010042585/article/details/79892073
通过ajax实现
html页面的JS代码如下:
<script
type=
"text/javascript"
>
$(
function(){
$(
'span').
click(
function (e) {
var nodeid =
$(e.
target).
attr(
'id')
;
//获取节点ID
$.
get(
"{%
url
"helpresult" %}
"
, {
'nodeid': nodeid}
,
function(ret){
$(
'.
results
').
html(
'')
;
//清空当前标签下的内容
$(
'.
results
').
append(ret)
;
//渲染后台数据到当前div下
})
;
})
;
})
;
</script>
view.py文件代码如下
def
helpresult(request):
nodeid = request.GET.get(
'nodeid') #接受前台出过来的ID
#写try except 是为了清除一个500错误
try:
helpcon = models.Area.objects.get(
id=nodeid).community #以ID为条件过滤,community是Area这张表里的字段
except:
helpcon =
''
return HttpResponse(helpcon)
在urls.py下添加:
url(
r'^helpresult/$'
,
views.helpresult
,
name
=
'helpresult'
)
,
到此渲染相应节点内容结束
效果图:
![](https://i-blog.csdnimg.cn/blog_migrate/98280efab308ce715162ec7d08fcf412.png)