【发布时间】:2011-03-10 08:30:31
【问题描述】:
我正在尝试在我的 grails 项目中实现async jQuery treeview。所以我的要求是在加载页面时我想提供以下结构:
-> Overview
-> Resources
--> User Activity
--> Network Sources
点击User Activity/Network Sources,它应该有以下孩子:
--> User Activity
---> By Day of Week
---> By Time of Day
.....
--> Network Resources
---> By Day of Week
---> By Time of Day
.....
现在资源的子列表应该来自控制器,因此我尝试使用以下代码:
<script type="text/javascript">
function initTrees() {
jQuery("#mixed").treeview({
url: "/.../.../getSubTreedata"
})
}
$(document).ready(function(){
initTrees();
});
</script>
<ul id="mixed">
<li><span>Overview</span></li>
<li id="36" class="hasChildren">
<span>Resources</span>
<ul>
<li><span class="placeholder"> </span></li>
</ul>
</li>
</ul>
控制器有以下代码:
def getSubTreedata = {
def jsonChild1 = [text:"By Day of Week"];
def jsonChild2 = [text:"By Time of Day"];
def jsonChild3 = [text:"Holiday"];
def jsonChild4 = [text:"Weekend"];
def jsonChild5 = [text:"Time Windows"];
def jsonResult = [
text: "User Activity",
expanded : false,
classes : "important",
children : [jsonChild1,jsonChild2,jsonChild3,jsonChild4,jsonChild5],
]
def convertedData = jsonResult as JSON
convertedData = new StringBuffer(convertedData.toString()).insert(0, "[");
convertedData = new StringBuffer(convertedData.toString()).insert(convertedData.length(), "]");
println "convertedData = "+convertedData;
render convertedData;
最终它的印刷
convertedData = convertedData = [{"text":"User Activity","expanded":false,"classes":"important","children":[{"text":"By Day of Week"},{"text":"By Time of Day"},{"text":"Holiday"},{"text":"Weekend"},{"text":"Time Windows"}]}]
但这不符合我的要求,我需要在控制器中创建一个数组并将其解析为 JSON 并返回...
任何帮助都将受到高度赞赏......
:更新: 现在我可以在 UI 上显示正确的树格式,但我的主要问题是如何显示所有孩子,即“按星期几”、“一天中的时间”等作为与 Ajax.Updater 的链接......我知道我需要更改实际上显示所有子项的 jquery.treeview.async.js 文件....但是我不知道如何将它们创建为链接并通过单击该链接来调用 Ajax.Updater ...
【问题讨论】:
标签: jquery grails groovy treeview