0

我有一个通过 ajax 调用返回的 xml 对象,其中包含 1 条记录、33 列(只有 1 条记录或没有),看起来像这样

    xml "<Table>
    <Supplier>false</Supplier>
    <Address>true</Address>
    <ProductInformation>true</ProductInformation>
    <ProductDetail>true</ProductDetail>
    <BusinessRef>true</BusinessRef>
    <RequiredLiveDate>true</RequiredLiveDate>
    <ActualLiveDateCheck>true</ActualLiveDateCheck>
    <ABEndCheck>true</ABEndCheck>
    <FloorRoomRackSpace>true</FloorRoomRackSpace>
    <PremisesNameNum>true</PremisesNameNum>
    <PremisesExists>true</PremisesExists>
    <IsSiteSecure>true</IsSiteSecure>
    <CheckTechPres>true</CheckTechPres>
    <CheckSepAndResil>true</CheckSepAndResil>
    <SuppConfSepAndRes>true</SuppConfSepAndRes>
    <DelDateContingency>true</DelDateContingency>
    <AwareOfTimeIssues>true</AwareOfTimeIssues>
    <VisitorsNames>true</VisitorsNames>
    <VisitorsTelNum>true</VisitorsTelNum>
    <VisitorsCompanyName>true</VisitorsCompanyName>
    <VisitorsNationality>true</VisitorsNationality>
    <VisitorsClearanceLvl>true</VisitorsClearanceLvl>
    <VisitorsCarReg>true</VisitorsCarReg>
    <SiteVisitSponserNme>true</SiteVisitSponserNme>
    <SiteVisitArrvalDate>true</SiteVisitArrvalDate>
    <SiteVisitTimeSart>true</SiteVisitTimeSart>
    <SiteVisitTimeEnd>true</SiteVisitTimeEnd>
    <WhichAreaToBeVisited>true</WhichAreaToBeVisited>
    <WhoIsToMeetVisitor>true</WhoIsToMeetVisitor>
    <FSSiteName>NA</FSSiteName>
    <WorkType>Cabling</WorkType>
    <VisitorContact>Alan Legg</VisitorContact>
    <SiteLocation>Tech Hall 1</SiteLocation>
</Table>"   String

这是提取数据的代码:

        function getExistingCheckList() {
        var PWNum = 'PW11896';
        var testddl = $("#testddl");
        $.ajax({
            type: "POST",
            url: "Circuits_OrderManagementTracker.aspx/getAnyChecklistRecords",
            data: "{'PWNum': '" + PWNum + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                var xmlDoc = $.parseXML(response.d);
                var xml = $(xmlDoc);
                var CheckListsReturned = xml.find("Table");

              $.each(CheckListsReturned, function (index, CheckListsReturned) {
                    ColumnName = $(this).find("title").????()
                    columnsData = $(this).find("title").????()
                    testddl.append('<option>' + ColumnName + '</option>');
                    testddl2.append('<option>' + columnsData + '</option>');
                });
            },
            failure: function (msg) {
                alert(msg);
            }
        });
    }

我希望遍历 xml,提取所有 33 列的列名和列值并填充 2 个下拉列表,但我在语法上苦苦挣扎,你能帮帮我吗?

4

1 回答 1

0
var checkListsReturned = xml.find("Table").children();
checkListsReturned.each(function() {
    var columnName = $(this)[0].tagName;
    var columnData = $(this).text();
    testddl.append('<option>' + ColumnName + '</option>');
    testddl2.append('<option>' + columnData + '</option>');
});
于 2013-03-26T15:36:41.373 回答