으로 처리하는 방법 :부모의 자식 노드를 얻고 나는이 XML 문서가 JQuery와 아약스
<?xml version="1.0" encoding="utf-8" ?>
<modules>
<sect>
<mod name="Weather">
<minWidth>200</minWidth>
<minHeight>200</minHeight>
</mod>
<mod name="Settings">
<minWidth>200</minWidth>
<minHeight>30</minHeight>
</mod>
</sect>
<sect>
<mod name="Social">
<minWidth>200</minWidth>
<minHeight>200</minHeight>
</mod>
</sect>
<sect>
<mod name="Show">
<minWidth>200</minWidth>
<minHeight>200</minHeight>
</mod>
<mod name="Puzzle">
<minWidth>200</minWidth>
<minHeight>200</minHeight>
</mod>
</sect>
</modules>
을하고 나는 그것이 JQuery와 아약스와 목록 요소로 자식 노드의와 모든 종파 노드를 표시합니다. 나는 다음과 같은 JS 코드를 시도 :
$.ajax({
type: "GET",
url: "/style/modules/start_page_modules.xml",
dataType: "xml",
success: function(xml){
$(xml).find('sect').each(function(){
$("<div></div>").html(function(){
$(this).find("mod").each(function(){
var mWidth = $(this).children("mod").find("minWidth").text();
var mHeight = $(this).children("mod").find("minHeight").text();
$("<li></li>").css({
width: mWidth,
height: mHeight
}).appendTo("sect");
});
}).appendTo("#main_content ul");
});
},
error: function() {
alert("An error occurred while processing XML file.");
}
});
을하고 일의 전부는 ul
요소와 다른 아무것도 세 sect
노드를 추가하는 것입니다. 나는 mod
노드과 같이 각각의 div가 될하려는 :
<div id="sect">
<li style="width: 200px;height:200px;"></li>
<li style="width: 200px;height:30px;"></li>
</div>
<div id="sect">
<li style="width: 200px;height:200px;"></li>
</div> .....and so on
내가 도움이 필요하세요 ...
__IDs 당신은 _i이 모드 노드에 있어야 할에 대한 전략을 변경해야 HTML__에서 고유해야합니다 그들의 각각의 분파 divs_ – Satpal
대단히 고마워,하지만 당신이 의미하는 것이 고유하지 않아야한다. id도'div' 엘리먼트의'id' 속성을 제외하면 아무 것도 바뀌지 않을 것입니다 ... – assetCorp