简体   繁体   English

jQuery:排序分层数据?

[英]jQuery: Sorting hierarchical data?

I have tried for some time to work out a way of sorting nested categories with jQuery. 我已经尝试了一段时间来找出一种使用jQuery对嵌套类别进行排序的方法。 I failed to build my own plugin to do this, so I tried to find something that were available already. 我没有构建自己的插件来做到这一点,所以我试图找到已经可用的东西。 Tried a few hours now with this one, http://www.jordivila.net/code/js/jquery/ui-widgetTreeList_inheritance/widgetTreeListSample.aspx and cant get it to work. 现在用这个试了几个小时, http://www.jordivila.net/code/js/jquery/ui-widgetTreeList_inheritance/widgetTreeListSample.aspx并且无法让它工作。

What are the alternatives of creating a jQuery / jQuery UI script that handles sorting children and parent categories in a way that can be combined with a AJAX PHP backend to handle the actual sorting in the database? 有哪些替代方法可以创建一个jQuery / jQuery UI脚本,以一种可以与AJAX PHP后端结合处理数据库中实际排序的方式处理子类和父类别的排序?

Thanks! 谢谢!

You could try structuring your hierarchical data in your database using the Nested Set Model, it will allow you to simply query your categories in order of their depth using single SELECT 您可以尝试使用嵌套集模型在数据库中构建分层数据,它允许您使用单个SELECT按照深度顺序查询类别

Here is an article from MySQL describing how it is implemented in a relational database http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/ 以下是MySQL的一篇文章,描述了它是如何在关系数据库中实现的.http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/

I used the widget from http://www.jordivila.net/jquery-widget-inheritance.html to sort nested categories and it worked for me. 我使用了来自http://www.jordivila.net/jquery-widget-inheritance.html的小部件来对嵌套类别进行排序,它对我有用。

Try using this simple html file 尝试使用这个简单的html文件

<script src="http://www.jordivila.net/code/js/jquery/ui-widgetTreeList/widgetTreeList.js" type="text/javascript"></script>
<script src="http://www.jordivila.net/code/js/jquery/ui-widgetTreeList_inheritance/widgetTreeList_Sort.js" type="text/javascript"></script>


<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/ui-lightness/jquery-ui.css" rel="stylesheet" type="text/css" />
<link href="http://www.jordivila.net/code/js/jquery/ui-widgetTreeList/widgetTreeList.css" rel="stylesheet" type="text/css" />

<style type="text/css">
    #treeListSortable {width:300px;}
</style>

    <script type="text/javascript">
        $(document).ready(function() {
        $('#treeListSortable').treeListSortable();
        });

    </script>

                <ul id="treeListSortable">
                      <li>Node 1
                        <ul>
                            <li>Node 12</li>
                            <li>Node 9</li>
                            <li>Node 7
                                <ul>
                                    <li>Node 6</li>
                                    <li>Node 11</li>
                                    <li>Node 10</li>
                                    <li class="ui-treeList-open">Node 8
                                    <ul>
                                        <li>Node 5</li>
                                        <li>Node 2</li>
                                        <li>Node 4</li>
                                        <li>Node 3</li>
                                    </ul>
                                    </li>
                                </ul>
                            </li>
                            <li>Node 13</li>
                        </ul>
                      </li>
                </ul>        

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM