dsk88199 2012-10-19 00:22
浏览 24
已采纳

Jquery可排序还原portlet到已保存的设置

There are plenty of posts here and on the web regarding how to SAVE the state of jquery sortable list but what about restoring one?

In my case I'm organizing a page layout, not a list, so I will have a left and right column (or more).

Here is what I have done in the past (using php+smarty):

<div id="leftsort">
    {section loop=$leftSort name="ls"}
        {if $leftSort[ls]}{include file="index/sort/`$leftSort[ls]`.tpl"}{/if}
    {/section}
</div>
<div id="rightsort">
    {section loop=$rightSort name="rs"}
        {if $rightSort[rs]}{include file="index/sort/`$rightSort[rs]`.tpl"}{/if}
    {/section}
</div>

Each portlet has its own template file thats included. When I save the state of the sortable list I save the left and right column separate to make it easier to restore.

How would you restore the sortable list?

I would prefer a pure jquery way of doing it, example - having the portlets hidden on the page, pass a json array to the sortable list and on 'create' have it sort and display the portlets

$( ".selector" ).sortable({
   create: function(event, ui) { 
     -- load sortable positions in a json array --
     -- parse the array and move the hidden portlets into position --
     -- show portlets --
   }
});

For me specific code is not exactly required so any concepts or ideas are appreciated.

Thank you!

-- Thinking like: http://jsfiddle.net/8gYsy/

  • 写回答

2条回答 默认 最新

  • doulao3905 2012-10-19 02:29
    关注

    I've managed to code up my concept tho I do hope there are some more answers! http://jsfiddle.net/Qwjp9/

    This would allow you to restore the saved positions based on a json array. All portlet elements would be loaded in a hidden div and moved. I added a save example too.

    var cols=jQuery.parseJSON('{"col1":["p1","p2"],"col2":["p3"]}');
    $( ".column" ).sortable({
        connectWith: ".column",
        create: function(){
            var colid=this.id;      
            var col=cols[colid];
            $.each(col, function(index, value) {
               $('#'+value).appendTo($('#'+colid));
            });
        }, 
        update: function() {
             $.get('saveSortable.php',
                  {col: this.id, sort:$(this).sortable('toArray').toString()});
        }                       
    });​
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 echarts动画效果失效的问题。官网下载的例子。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加