2013-02-28 17 views
0

我需要在存在的許多根文件夾中獲取特定的書籤組或文件夾「codebase」。另外,我需要在「codebase」下面顯示它的子文件夾或子組到我的Popup html表單中。從鉻文件,我相信下面的功能可以做的東西,但它需要文件夾的ID,如何獲得ID?在Chrome擴展中篩選特定的書籤文件夾項目

chrome.bookmarks.getSubTree(string id, function callback) 

僅供參考,彈出的html表單由腳本在外部控制,我需要將代碼放在上面的要求中。 感謝您的時間!

回答

0

我用下面的代碼解決了這個問題,任何人都可以通過檢查這個答案的「正確」符號或者通過評論來證明下面的代碼。

var temP = []; 
    var found; 
    $(document).ready(function(){ 
    chrome.bookmarks.getTree(function(bookmarks){ 
     found = search_for_title(bookmarks, "here goes title of an existing bookmark which user need to search"); // found variable will have the id of bookmark we r searching. 
     chrome.bookmarks.getChildren(found, function(children) { //using the ID of the bookmark we can process further requirement 
      children.forEach(function(bookmark) { // here i'm dwelling into sub folder to extract the content 
      console.debug(bookmark.title);// these were the subfolder titles 
      console.log(bookmark.id);// these were the subfolder ids 
      }); 
     }); 
    }); 

    function search_for_title(bookmarks, title){ // first argument is entire bookmarks, second argument is title which we specified for search 
     for(var i=0; i < bookmarks.length; i++){ 
      if(bookmarks[i].title == title){ 
      return bookmarks[i].id; // we will get the id of the bookmark we are searching for 
      } 
      else{ 
       if(bookmarks[i].children){ 
        var id = search_for_title(bookmarks[i].children, title); 
        if(id) 
        return id; 
       } 
      } 
     } 

    return false; 
    } 
}); 

感謝

相關問題