2014-09-21 40 views
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新添加的项目不会移动

我冲这 - >nestedsortable dynamic item not collapsing

我无法事件使FUNC “nextid”,它的工作原理....

我所missig。

Thansk

回答

1

我thinck这是你的问题: 中的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!'); 
     } } 
+0

没有工作。:/ – freezer 2014-09-21 18:51:07

+0

不把函数放到document.ready! – amir2h 2014-09-21 19:06:40

+0

我已经没有'我使用纯JQuery可排序插件,它工作正常,但我需要一些嵌套可排序的东西。 – freezer 2014-09-21 19:25:33

0

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