0

脚本 :

function initializeSort() {
    jQuery('#apps').sortable().bind('sortupdate', function () {
        // Save order in extension when apps are moved
        var children = document.getElementById("#apps").innerHTML;
        console.log(children);
        chrome.runtime.sendMessage({
            type: "updateApps",
            data: children
        });
    });
}

我得到这个错误,

Uncaught TypeError: Cannot read property 'innerHTML' of null 

我唯一能想到的是,这与.sortable()我从这里使用的代码有关, http: //farhadi.ir/projects/html5sortable/,因为在我使用.sortable()元素之前它工作正常。

4

2 回答 2

0

无论我做了什么,它总是会给我一个元素为空错误或使用 jQuery 无法转换圆形对象错误。

我仍然不明白为什么,但是在拉了很多头发之后,我能够让它与它一起工作,

jQuery('#apps').sortable().bind('sortupdate', function(){ 
    chrome.runtime.sendMessage({ type: "updateApps", data: { list: jQuery("#apps").html()   } });
});

因此,对于其他有同样问题的人,我认为通过 JSON 发送数据的最佳方式是使用对象或对象数组,您不必担心这种方式的类型。

于 2013-11-12T16:43:43.377 回答
0

为什么不直接使用 jquery 来获取孩子?

$(document).ready(function() {
 jQuery('#apps').sortable().bind('sortupdate', function () {
     // Save order in extension when apps are moved
     var children = $("#apps").children();
     console.log(children);
     chrome.runtime.sendMessage({
         type: "updateApps",
         data: children
     });
 });
});

http://jsfiddle.net/ZuYpm/

于 2013-11-11T21:22:57.013 回答