如何将另一个节点内xml节点的属性映射到jqgrid中的列

如何将另一个节点内xml节点的属性映射到jqgrid中的列,jqgrid,xml-parsing,Jqgrid,Xml Parsing,下面是我想映射到jqGrid中的列的XML: <ProtoRequestInfo NPO = "102922"> <ProtoRequest No = "84P6-11-00002" Requestor = "Daniel Frank(E677648)" CustomerName = "TLV BMW" CustomerOrder = "" MWO = "4601302" P

下面是我想映射到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>


您可以为列
saleorder
Date
Quantity
指定
xmlmap
属性,并将
xmlmap
定义为函数。该函数将获取主元素(我不确定
)作为参数。您可以在
xmlmap
中获取所需的属性,并从函数
xmlmap
返回该属性

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

更新的:显示如何以您发布的格式读取XML数据。结果如下图所示

我在演示中使用了以下代码:

$(“#列表”).jqGrid({
数据类型:“xml”,
url:“ReadAttrFromXml.xml”,
gridview:没错,
自动编码:正确,
高度:“自动”,
rowNum:10000,//无本地分页
colModel:[
{name:“No”,xmlmap:function(obj){
返回美元(obj).attr(“否”);
}},
{name:“请求者”,宽度:130,xmlmap:function(obj){
返回$(obj).attr(“请求者”);
}},
{name:“CustomerName”,宽度:120,xmlmap:function(obj){
返回美元(obj).attr(“客户名称”);
}},
{name:“SalesOrder”,xmlmap:function(obj){
return$(obj).find(“>Production”).attr(“SalesOrder”);
}},
{name:“Date”,formatter:“Date”,formattoptions:{srcformat:“d-M-Y”},align:“center”,
sorttype:“日期”,
xmlmap:函数(obj){
返回$(obj).find(“>Production>RequestedDeliveryDetails”).attr(“日期”);
}},
{name:“Quantity”,格式化程序:“integer”,sorttype:“integer”,align:“right”,
xmlmap:函数(obj){
返回$(obj).find(“>Production>RequestedDeliveryDetails”).attr(“数量”);
}}
],
cmTemplate:{宽度:100},
xmlReader:{
root:“ProtoRequestInfo”,
行:“ProtoRequest”,
重复项:false,
id:“[否]”
}
});

最重要的是
xmlmap
函数和
xmlReader

colModel:[{name:'No',index:'No',width:80,xmlmap:'No]},{name:'Requestor',index:'Requestor',width:80,xmlmap:'Requestor]},{name:'CustomerName',index:'CustomerName',width:80,xmlmap:'CustomerName]}]{root:“ProtoRequestInfo”,row:“ProtoRequest”,repeatitems:false}我已经添加了colModel和xmlReader,如上所述。您能帮我映射ProtoRequest标签子项下的销售订单吗?如果我为“row”提供“ProtoRequest”属性在xmlReader中我可以访问它的属性。类似地,我如何访问“ProtoRequest”标记的子标记“Production”标记的属性?@user2111302:查看我答案的更新部分。