0
var menu = $("ol.menu").nestedSortable({
            handle: '.move',
            items: 'li',
            placeholder: 'placeholder',
            opacity: 0.7,
            toleranceElement: '> i',
            connectWith: 'ol',
            isTree: true,
        }).disableSelection();

        $('#addMenu').on('click',function(){
            var text = $('#menuText').val();
            var link = encodeURIComponent($('#menuLink').val()); 
            if(text != '' && link !=''){
                var html = $('<li id="menu_'+(parseInt(menu.children.length)+2)+'" class="mjs-nestedSortable-leaf">')
                            .append($('<i class="glyphicon glyphicon-move">'),
                                    '&nbsp;'+text+' - '+link,
                                    $('<span class="remove-btn removeMenu">')
                                        .append('<i class="glyphicon glyphicon-minus">'),
                                    $('<ol>')                                        
                            );
                menu.append($(html));
                menu.nestedSortable('refresh');
                console.log(menu.nestedSortable('toArray'));
                $('#menuText').val('');$('#menuLink').val('');
            }else{
                alert('Menü Başlığı ve link boş bırakılamaz!');
            }

        });

我已经红了我能找到的任何东西。但一切都没有改变。我正在将新项目添加到列表中,但无法将其移动到可排序容器中。页面加载附带的元素很好,它们是可移动的。如何让它发生。

我把它变红了-> nestedsortable 动态项不折叠

我无法使 func "nextId" 起作用....

我是什么小姐。

坦斯克

4

2 回答 2

1

我认为这是你的问题:document.ready 中的所有代码在页面加载时都可以工作。但是当你附加一些东西时它不起作用!最简单的方法是:

你应该在你的代码中添加这样的东西:

<div id="addmenu" onclick="yourfunction()" > </div>

js:

 function yourfunction(){
        var text = $('#menuText').val();
        var link = encodeURIComponent($('#menuLink').val()); 
        if(text != '' && link !=''){
            var html = $('<li id="menu_'+(parseInt(menu.children.length)+2)+'" class="mjs-nestedSortable-leaf">')
                        .append($('<i class="glyphicon glyphicon-move">'),
                                '&nbsp;'+text+' - '+link,
                                $('<span class="remove-btn removeMenu">')
                                    .append('<i class="glyphicon glyphicon-minus">'),
                                $('<ol>')                                        
                        );
            menu.append($(html));
            menu.nestedSortable('refresh');
            console.log(menu.nestedSortable('toArray'));
            $('#menuText').val('');$('#menuLink').val('');
        }else{
            alert('Menü Başlığı ve link boş bırakılamaz!');
        } }
于 2014-09-21T18:23:38.487 回答
0

我真的很愚蠢。我刚刚忘记了动态var html中句柄的类名“move”:(..我现在解决了。

于 2014-09-21T21:12:04.767 回答