2

下面是我想映射到 jqGrid 中的列的 XML:

<ProtoRequestInfo NPO = "102922">
    <ProtoRequest
        No = "84P6-11-00002"
        Requestor = "Daniel Frank(E677648)"
        CustomerName = "TLV BMW"
        CustomerOrder = ""
        MWO = "4601302"
        PartNumber = "813818-0003"
        ProductType = "CHRA"
        CreationDate = "12-May-2011"
        ABCClasification = "B - Durability testing / Production supplier-soft tooling"
        ProtoStatus = "Closed"
        UsageType = "Assembly Request"
        BOMAvailabilityDate = "13-May-2011"
        BOMCommitedDate = ""
        Technology = "VNT Step3 REA"
        Plant = "84P6-Thaon Les Vosges"
        EstimatedBudget_USD = "0.00">
        <Production
            No = "102219281"
            Status = "Closed"
            SalesOrder = ""
            <RequestedDeliveryDetails Date = "01-Aug-2011" Quantity = "48"/>
            <AgreedDetails Date = "29-Sep-2011" Quantity = "48"/>
            <EstimatedDetails Date = "24-Aug-2011" Quantity = "47.0"/>
            <EstimatedDetails Date = "20-Sep-2011" Quantity = "1.0"/>
            <Info>No Qty Shipped</Info>
        </Production>
    </ProtoRequest>
</ProtoRequestInfo>

colmodel 应该如何将以下内容映射到列中?

  1. 生产标签下的销售订单
  2. 请求的交付详细信息标签下的日期
  3. 请求的交货详细信息标签下的数量
4

1 回答 1

1

xmlmap您可以为 columns指定属性SalesOrderDateQuantity定义xmlmap为函数。该函数将获取主要元素(我不确定<ProtoRequestInfo><ProtoRequest>)作为参数。您可以在其中获取所需的属性xmlmap并从函数中返回它xmlmap

您可以在答案中找到使用 XML 属性的示例(请参阅演示)。

UPDATED: The demo shows how to read XML data in the format which you posted. The results are like on the picture below

enter image description here

I used the following code in the demo:

$("#list").jqGrid({
    datatype: "xml",
    url: "ReadAttrFromXml.xml",
    gridview: true,
    autoencode: true,
    height: "auto",
    rowNum: 10000, // no local paging
    colModel: [
        {name: "No", xmlmap: function (obj) {
            return $(obj).attr("No");
        }},
        {name: "Requestor", width: 130, xmlmap: function (obj) {
            return $(obj).attr("Requestor");
        }},
        {name: "CustomerName", width: 120, xmlmap: function (obj) {
            return $(obj).attr("CustomerName");
        }},
        {name: "SalesOrder", xmlmap: function (obj) {
            return $(obj).find(">Production").attr("SalesOrder");
        }},
        {name: "Date", formatter: "date", formatoptions: {srcformat: "d-M-Y"}, align: "center",
            sorttype: "date",
            xmlmap: function (obj) {
                return $(obj).find(">Production>RequestedDeliveryDetails").attr("Date");
            }},
        {name: "Quantity", formatter: "integer", sorttype: "integer", align: "right",
            xmlmap: function (obj) {
                return $(obj).find(">Production>RequestedDeliveryDetails").attr("Quantity");
            }}
    ],
    cmTemplate: {width: 100},
    xmlReader: {
        root: "ProtoRequestInfo",
        row: "ProtoRequest",
        repeatitems: false,
        id: "[No]"
    }
});

The most important are implementations of xmlmap functions and xmlReader.

于 2013-02-26T13:15:47.933 回答