jQuery可排序Portlet+创建动态新Portlet

jQuery sortable portlets + creating dynamic new portlets

本文关键字:动态 Portlet 创建 Portlet+ 排序 jQuery      更新时间:2023-09-26

为了简化问题,让我们假设我们使用的代码与jquery ui portlet小部件完全相同:

http://jqueryui.com/sortable/#portlets

我在stackoverflow中读到了另一个关于主题的帖子,但它真的没有给我一个关于如何处理解决方案的线索,因为原始代码已经不可用了

jQuery如何添加portlet

让我们想象一下向现有列添加新portlet的最简单方法:

$( "#col0" ).append($('<div class="portlet ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" id="p5">' +
                '<div class="portlet-header ui-widget-header ui-corner-all">' +
                '<span class="ui-icon ui-icon-minusthick"></span>' + "my title" + '</div>' +
                '<div class="portlet-content">' + "my content" + '</div></div>'))

使用这种方法,我必须解决一些重要问题:

  1. 标题右角的"+"按钮不适用于新的Portlet。

  2. 标题和内容文本不会保留在div内部。当文本到达div的边缘时,它会继续在外部。

  3. 我试图通过在stackoverflow中获得的这种方法来获得portlet的顺序。当您只使用默认的jqueryportlet加载应用程序时,它就可以工作了。

    $( ".column" ).sortable({
    connectWith: ".column",
    delay: 150,
    start: function(event, ui) {
            ui.item.startPos = ui.item.index();
            item = ui.item;
            newList = oldList = ui.item.parent();
    },
    stop: function(event, ui) {
            /*saveOrder();*/        
            console.log("Start position: " + ui.item.startPos);
            console.log("New position: " + ui.item.index());
    },
    change: function(event,ui) {
            if(ui.sender) newList = ui.placeholder.parent();
    

    },

在添加新portlet之前和之后,当我尝试获取可排序的列元素时:

    $("#obtain").button().click(function() {
         console.log($("#col0").sortable('toArray').toString());});

它为我提供了每列正确数量的元素(添加了新的元素(,但当我试图在列之间移动新的元素时,当你以普通的方式创建新元素时,列中的位置是没有意义的。我认为,每次创建新的portlet时,我都应该再次执行start((函数,这样我就可以获得正确的索引。但我不知道该怎么做。

非常感谢你抽出时间,我希望我能得到一些建议,

关于

对于#1我认为您错过了portlet切换类

<span class="ui-icon ui-icon-minusthick">

应该是

<span class='ui-icon ui-icon-minusthick portlet-toggle'>