Jquery 可嵌套插件

Jquery 可嵌套插件,jquery,cookies,jquery-nestable,Jquery,Cookies,Jquery Nestable,已解决 我有一个问题 是否可以在“展开”和“折叠”时将可嵌套jQuery插件与jQuery Cookie一起使用? 记住“展开”和“折叠”的位置 链接到脚本: 谢谢你的回答 这是带有cookie保存的脚本: expandItem: function(li) { li.removeClass(this.options.collapsedClass); li.children('[data-action="expand"]').hide();

已解决

我有一个问题

是否可以在“展开”和“折叠”时将可嵌套jQuery插件与jQuery Cookie一起使用? 记住“展开”和“折叠”的位置

链接到脚本:

谢谢你的回答

这是带有cookie保存的脚本:

expandItem: function(li)
    {
        li.removeClass(this.options.collapsedClass);
        li.children('[data-action="expand"]').hide();
        li.children('[data-action="collapse"]').show();
        li.children(this.options.listNodeName).show();
        if(getCookie("tree") != null){
            var CookieValue = getCookie("tree") + li.attr('data-id') + ",";
        }
        else{
            var CookieValue = li.attr('data-id') + ",";
        }
        $.cookie("tree", CookieValue, {expires:3600, path:'/administrator/'});
    },

    collapseItem: function(li, a)
    {
        var lists = li.children(this.options.listNodeName);
        if (lists.length) {                
            li.addClass(this.options.collapsedClass);
            li.children('[data-action="collapse"]').hide();
            li.children('[data-action="expand"]').show();
            li.children(this.options.listNodeName).hide();
            if(getCookie("tree") != null){
                var CookieValueArray = getCookie("tree").split(",");
                for(i=0;i<CookieValueArray.length;i++){
                    if(CookieValueArray[i] == li.attr('data-id') && a == true){
                        li.children('[data-action="expand"]').hide();
                        li.children('[data-action="collapse"]').show();
                        li.children(this.options.listNodeName).show();
                    }
                }
                if(a != true){
                    var CookieValue = "";
                    for(i=0;i<CookieValueArray.length-1;i++){
                        if(CookieValueArray[i] != li.attr('data-id')){
                            CookieValue += CookieValueArray[i] + ",";
                        }
                    }
                    if(CookieValue == ""){
                        $.cookie("tree", "", {expires:-1, path:'/administrator/'});
                    }
                    else{
                        $.cookie("tree", CookieValue, {expires:3600, path:'/administrator/'});
                    }
                }
            }
        }
    },
expandItem:功能(li)
{
removeClass(this.options.collapsedClass);
li.children('[data action=“expand”]').hide();
li.children('[data action=“collapse”]').show();
li.children(this.options.listNodeName.show();
if(getCookie(“树”)!=null){
var CookieValue=getCookie(“树”)+li.attr('data-id')+“,”;
}
否则{
var CookieValue=li.attr('data-id')+“,”;
}
$.cookie(“树”,CookieValue,{expires:3600,路径:'/administrator/'});
},
collapseItem:函数(li,a)
{
var list=li.children(this.options.listNodeName);
if(lists.length){
li.addClass(this.options.collapsedClass);
li.children('[data action=“collapse”]').hide();
li.children('[data action=“expand”]').show();
li.children(this.options.listNodeName.hide();
if(getCookie(“树”)!=null){
var CookieValueArray=getCookie(“树”).split(“,”);
对于(i=0;iYes)

我认为您必须通过添加折叠状态来更改序列化函数

serialize: function()
    {
        var data,
            depth = 0,
            list  = this;
            step  = function(level, depth)
            {
                var array = [ ],
                    items = level.children(list.options.itemNodeName);
                items.each(function()
                {
                    var li   = $(this),
          // Check if dd-collapse is part of the class of the <li> element
                        var collapsed = "open";
                        if(li.hasClass( "dd-collapsed" ){
                          collapsed = "collapsed";
                        }
                        item = $.extend({}, li.data(), collapsed),
                        sub  = li.children(list.options.listNodeName);
                    if (sub.length) {
                        item.children = step(sub, depth + 1);
                    }
                    array.push(item);
                });
                return array;
            };
        data = step(list.el.find(list.options.listNodeName).first(), depth);
        return data;
    }
当然,您必须在可嵌套的jquery.cookie.js之前加载jquery.cookie.js

我没有试过,但它在我的头脑中起作用……;)

是的

我认为您必须通过添加折叠状态来更改序列化函数

serialize: function()
    {
        var data,
            depth = 0,
            list  = this;
            step  = function(level, depth)
            {
                var array = [ ],
                    items = level.children(list.options.itemNodeName);
                items.each(function()
                {
                    var li   = $(this),
          // Check if dd-collapse is part of the class of the <li> element
                        var collapsed = "open";
                        if(li.hasClass( "dd-collapsed" ){
                          collapsed = "collapsed";
                        }
                        item = $.extend({}, li.data(), collapsed),
                        sub  = li.children(list.options.listNodeName);
                    if (sub.length) {
                        item.children = step(sub, depth + 1);
                    }
                    array.push(item);
                });
                return array;
            };
        data = step(list.el.find(list.options.listNodeName).first(), depth);
        return data;
    }
当然,您必须在可嵌套的jquery.cookie.js之前加载jquery.cookie.js


我没有尝试过,但它在我的头脑中工作…;)

这当然是可能的,但需要扩展插件源代码,我想。插件源代码在这个链接上这当然是可能的,但需要扩展插件源代码,我想。插件源代码在这个链接上,谢谢你的帮助,但这不起作用。当我添加这个时,我s树已展开。问题在序列化函数中。这是cookie值“%5Object%20Object%5D%2C%5Object%20Object%5D%2C%5Object%20Object%5D”感谢您的帮助,但这不起作用。当我添加时,这是树已展开。问题在序列化函数中。这是cookie值“%5Object%20Object%5D%2C%5Object%20Object%5D%2C%5Object%20Object%5D”