2017-10-15 55 views
0

我正面臨一個小問題。當我在Google Chrome瀏覽器中右鍵單擊該頁面並按檢查(頁面的源代碼)時,出現以下錯誤。這個文件(ui-nestable.min.js)是我的頁面正常工作所需的,它的有趣的一面是我的頁面正常工作。我在互聯網上進行了研究,但沒有發現此錯誤的任何結果。未捕獲TypeError:無法讀取屬性'val'的undefined(ui-nestable.min.js)

Error Image

UI-nestable.min-JS代碼:

var UINestable = function() { 

var updateOutput = function (e) { 
    var list = e.length ? e : $(e.target), 
     output = list.data('output'); 
    if (window.JSON) { 
     output.val(window.JSON.stringify(list.nestable('serialize'))); //, null, 2)); 
    } else { 
     output.val('JSON browser support required for this demo.'); 
    } 
}; 


return { 
    //main function to initiate the module 
    init: function() { 

     // activate Nestable for list 1 
     $('#nestable_list_1').nestable({ 
      group: 1 
     }) 
      .on('change', updateOutput); 

     // activate Nestable for list 2 
     $('#nestable_list_2').nestable({ 
      group: 1 
     }) 
      .on('change', updateOutput); 

     // output initial serialised data 
     updateOutput($('#nestable_list_1').data('output', $('#nestable_list_1_output'))); 
     updateOutput($('#nestable_list_2').data('output', $('#nestable_list_2_output'))); 

     $('#nestable_list_menu').on('click', function (e) { 
      var target = $(e.target), 
       action = target.data('action'); 
      if (action === 'expand-all') { 
       $('.dd').nestable('expandAll'); 
      } 
      if (action === 'collapse-all') { 
       $('.dd').nestable('collapseAll'); 
      } 
     }); 

     $('#nestable_list_3').nestable(); 

    } 

}; 

}(); 

jQuery(document).ready(function() {  
    UINestable.init(); 
}); 
+0

此線'output.val(window.JSON.stringify(list.nestable( '序列化'))); //,null,2))'沒有找到數據,所以它是空的 – Saif

回答

0

您不要使用所有嵌套列表頁面。 你必須刪除所有額外的代碼。 像

var UINestable = function() { 

     var updateOutput = function (e) { 
      var list = e.length ? e : $(e.target), 
       output = list.data('output'); 
      if (window.JSON) { 
       output.val(window.JSON.stringify(list.nestable('serialize'))); //, null, 2)); 
      } else { 
       output.val('JSON browser support required for this demo.'); 
      } 
     }; 

     return { 
      //main function to initiate the module 
      init: function() { 

       // activate Nestable for list 1 
       $('#nestable_list_1').nestable({ 
        group: 1 
       }).on('change', updateOutput); 

       // output initial serialised data 
       updateOutput($('#nestable_list_1').data('output', $('#nestable_list_1_output'))); 

       $('#nestable_list_menu').on('click', function (e) { 
        var target = $(e.target), 
         action = target.data('action'); 
        if (action === 'expand-all') { 
         $('.dd').nestable('expandAll'); 
        } 
        if (action === 'collapse-all') { 
         $('.dd').nestable('collapseAll'); 
        } 
       }); 
      } 
     }; 
    }(); 
    jQuery(document).ready(function() {  
     UINestable.init(); 
    }); 
相關問題