0

多くのルート フォルダが存在する中で、特定のブックマーク グループまたはフォルダ「codebase」を取得する必要があります。また、「コードベース」の下のサブフォルダーまたはサブグループをポップアップ HTML フォームに表示する必要があります。chrome docs から、以下の関数で実行できると思いますが、フォルダーの ID が必要です。ID を取得するにはどうすればよいですか?

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

参考までに、ポップアップ HTML フォームはスクリプトによって外部から制御されているため、上記の要件のコードを配置する必要があります。御時間ありがとうございます !!!

4

1 に答える 1

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;
    }
});

ありがとう

于 2013-03-01T09:11:19.113 に答える