jQuery:对分层数据进行排序?

发布于 2024-09-04 14:48:49 字数 425 浏览 2 评论 0原文

我已经尝试了一段时间来找出一种使用 jQuery 对嵌套类别进行排序的方法。我未能构建自己的插件来执行此操作,因此我尝试找到已经可用的东西。现在尝试了几个小时,http://www .jordivila.net/code/js/jquery/ui-widgetTreeList_inheritance/widgetTreeListSample.aspx 并无法让它工作。

创建 jQuery / jQuery UI 脚本来处理排序子类别和父类别的方法有哪些,并且可以与 AJAX PHP 后端结合起来处理数据库中的实际排序?

谢谢!

I have tried for some time to work out a way of sorting nested categories with 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.

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?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

高速公鹿 2024-09-11 14:48:49

您可以尝试使用嵌套集模型在数据库中构建分层数据,它将允许您使用单个 SELECT 按深度顺序简单地查询类别

这是 MySQL 的一篇文章,描述了如何在关系数据库中实现它
http://mikehillyer.com/articles/managing-hierarchical-data-in -mysql/

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

Here is an article from MySQL describing how it is implemented in a relational database
http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/

双手揣兜 2024-09-11 14:48:49

我使用了 http://www.jordivila.net/jquery-widget-inheritance 中的小部件.html 对嵌套类别进行排序,它对我有用。

尝试使用这个简单的 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>        

I used the widget from http://www.jordivila.net/jquery-widget-inheritance.html to sort nested categories and it worked for me.

Try using this simple html file

<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>        

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文