2014-09-21 31 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中的句柄:(我現在解決了。