有人帮我吗?
我有 2 个步骤的 xml。例子 :
<listgroup title="Lifestyle" shortnote="">
<list>Type of Company: Architects may be self-employed.</list>
<list>Workspace – Indoors/outdoors: Architects work both.</list>
<list>Environment
<sublistgroup>
<sublist>Travel: Architects often visit construction sites to review the progress of projects.</sublist>
<sublist>People: They work a lot with other professionals involved in the construction project including engineers, contractors, surveyors and landscape architects.</sublist>
<sublist>Casual: They usually work in a casual and comfortable environment.</sublist>
<sublist>Hours: The hours are varied based on the project they are working on.</sublist>
<sublist>Physically demanding: They stand on their feet.</sublist>
<sublist>Tools: Computers - Architects </sublist>
</sublistgroup>
</list>
<list>Assist clients in obtaining construction bids</list>
<list>Observe, inspect and monitor building work</list>
在我的功能中,我使用“list.each”附加到 ul+index。它工作正常。我的问题是,当我附加“list.each”时,“sublistgroup”不应该附加到“list.each”,插入“sublistgroup”需要制作“ul”并且在ul中我需要“sublist”成为孩子们的..
我的代码在这里...
我知道,我做错了..请任何人纠正它并让我知道..
$(function(){
$.get('career-utility.xml',function(myData){
$(myData).find('listgroup').each(function(index){
var count = index;
var listGroup = $(this);
var listGroupTitle = $(this).attr('title');
var shortNote = $(this).attr('shortnote');
var subLink = $(this).find('sublist');
var firstList = $(this).find('list');
$('.grouplist').append('<div class="list-group"><h3>'+listGroupTitle+'</h3><ul class="level-one level' + count + '"></ul></div>');
firstList.each(function(listnum){
var subList = $(this).text();
var subListLeveltwo = $(this).find('sublist').text();
if(subListLeveltwo==''){
$('<li>'+subList+'</li>').appendTo('ul.level'+count+'');
}
else{
$('<li class="new">'+subList+'</li>').appendTo('ul.level'+count+'');
}
})
})
})
})