2013-10-18 6 views
0

탐색 창을 만들 수 있습니다 나에게 내 모든 사이트 및 subsits의 목록을 제공 :구문 분석 데이터 내가이 XML 응답이

https://hosted.demo.ca 
https://hosted.demo.ca/academic 
https://hosted.demo.ca/academic/bm 
https://hosted.demo.ca/academic/cmtte 
https://hosted.demo.ca/academic/dm 
https://hosted.demo.ca/academic/pm 
https://hosted.demo.ca/archive 
https://hosted.demo.ca/associations 
https://hosted.demo.ca/associations/bm 
https://hosted.demo.ca/associations/dm 
https://hosted.demo.ca/associations/pm 
내가 사이트 탐색 메뉴를 만들려면이 정보를 통해 이동 및 UL 및 선형 태그를 추가 할 수있는 방법

? XML을 가져 오는 데 사용

JS가 :

function getAllSites(){ 
    $().SPServices({ 
    operation: "GetAllSubWebCollection", 
    async: true, 
     completefunc: function(xData, Status){ 
     $(xData.responseXML).find("Web").each(function(){ 
     console.log($(this).attr("Url")); 
     }); 
    } 
    }); 
} 

답변

0

간단한 솔루션은 링크의 깊이에 따라 인덱스의지도를 구축하는 것, 깊이는 url/의 수에 의해 결정됩니다.

var map = {}; //init the map 
for (var i = 0, l = webs.length; i < l; i++) { 
    //we create a index for our links based on the depth of them by `/` 
    var m = webs[i].attributes['Url'].value.substring(23, webs[i].attributes['Url'].value.length).split('/').length; 

    map[m] = map[m] || []; //make sure we leave alone the old values if there is none init with new array 
    map[m].push(webs[i].attributes['Url'].value); //push new value to node 
} 
console.log(map); 

console.log(map);가 출력이 유사한 목적이에서

{ 
    "1": ["https://hosted.demo.ca", "https://hosted.demo.ca/academic", "https://hosted.demo.ca/archive", ...], 
    "2": ["https://hosted.demo.ca/academic/bm", "https://hosted.demo.ca/academic/cmtte", ...], 
} 

당신은 요소의 목록을 만들 수 있습니다.

+0

당신은 내가하려고하는 것에 꽤 가깝습니다. 그러나 당신이 모든 수준을 함께 그룹화하고 싶다고 가르친 것처럼 보입니다. (즉, 모든 레벨 1이 함께 앉아 모든 lv2 사이트가 더 원활하게 작동합니다.) 정확히 달성하려는 것은 아닙니다. 내가 의미하는 바를 보여주기 위해 나의 OP를 업데이트했다. – Batman