JQGrid多值列连接选择器

时间:2012-11-09 22:49:59

标签: jquery jqgrid selector concatenation xmlreader

这是我的问题:

我有一个像这样的XMLReader:

root: "response>claims",
row: "claim",
repeatitems: false,
id: "claimId"

和这样的XML数据结构:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<response>
    <claims>
        <claim>
            <actions />
            <adjusters />
            <claimId>254</claimId>
            <parties />
            <claimSubmitInd>N</claimSubmitInd>
            <claimTypeCd>AUTO</claimTypeCd>
            <units>
                <unit>
                    <claimId>254</claimId>
                    <insertId>sselvaraj</insertId>
                    <insertTmstmp>2012-10-24 18:07:47.167</insertTmstmp>
                    <roleCategory>veh_1st</roleCategory>
                    <sourceSystemCd>FNOL</sourceSystemCd>
                    <unitCategory>veh</unitCategory>
                    <coverages />
                    <damages />
                    <unitDataType>veh</unitDataType>
                    <unitId>1</unitId>
                    <unitSubType>sch</unitSubType>
                    <unitType>veh</unitType>
                    <updateId>sselvaraj</updateId>
                    <updateTmstmp>2012-10-24 18:07:47.167</updateTmstmp>
                </unit>
                <unit>
                    <claimId>254</claimId>
                    <insertId>sselvaraj</insertId>
                    <insertTmstmp>2012-10-24 18:14:07.437</insertTmstmp>
                    <roleCategory>veh_1st</roleCategory>
                    <sourceSystemCd>FNOL</sourceSystemCd>
                    <unitCategory>veh</unitCategory>
                    <coverages />
                    <damages />
                    <unitDataType>veh</unitDataType>
                    <unitId>2</unitId>
                    <unitSubType>sch</unitSubType>
                    <unitType>veh</unitType>
                    <updateId>sselvaraj</updateId>
                    <updateTmstmp>2012-10-24 18:14:07.437</updateTmstmp>
                </unit>
                <unit>
                    <claimId>254</claimId>
                    <insertId>sselvaraj</insertId>
                    <insertTmstmp>2012-10-24 18:17:47.597</insertTmstmp>
                    <roleCategory>veh_1st</roleCategory>
                    <sourceSystemCd>FNOL</sourceSystemCd>
                    <unitCategory>veh</unitCategory>
                    <coverages />
                    <damages />
                    <unitDataType>veh</unitDataType>
                    <unitId>3</unitId>
                    <unitSubType>sch</unitSubType>
                    <unitType>veh</unitType>
                    <updateId>sselvaraj</updateId>
                    <updateTmstmp>2012-10-24 18:17:47.597</updateTmstmp>
                </unit>
            </units>
            <clmAdjUserId>0</clmAdjUserId>
            <companyCd>06</companyCd>
            <injuryInd>N</injuryInd>
            <insInjAsPasInd>N</insInjAsPasInd>
            <insInjAsPedInd>N</insInjAsPedInd>
            <keyedDt>2012-10-24</keyedDt>
            <lossTmUnkInd>N</lossTmUnkInd>
            <othPropDmgInd>N</othPropDmgInd>
            <polFireAtSceneInd>N</polFireAtSceneInd>
            <rptOnlyInd>N</rptOnlyInd>
            <towClaimInd>N</towClaimInd>
            <witnessInd>N</witnessInd>
        </claim>
    </claims>
    <request>
        <expand>claim,units</expand>
        <filter>claimId eq 254</filter>
        <format>xml</format>
        <orderBy>claimId desc</orderBy>
        <orderByCol>claimId</orderByCol>
        <orderByDir>desc</orderByDir>
        <top>10</top>
    </request>
</response>

如果我的列定义如下:

    colModel: [
        { 
            name:  "claimId", 
            index:  "claimId", 
            width: 20, 
            xmlmap: ">claimId", 
            align: "right",
            sorttype: 'int',                
            hidden: false,
            searchoptions: {
                sopt: soptnums,
                attr: {style: "text-align: right;"}
            }                
        }
        ,{ 
            name:  "unitId", 
            index:  "unitId", 
            width: 20, 
            xmlmap: "units>unit>unitId", 
            align: "center",
            sorttype: 'int',                
            hidden: false,
            searchoptions: {
                sopt: soptnums,
                attr: {style: "text-align: center;"}
            }                
        }

然后我看到claim id节点值很好,并且单位集合中unitId节点值的所有相应匹配的串联。

所以,我看到像

这样的东西
Claim Id           Unit Id

254                123

我的问题是:如何为UnitId xmlmap编写选择器,以便连接产生类似“1 | 2 | 3”或“1分隔符2分隔符3”的字符串? 我尝试了几件事,例如,我看到xmlmap:“units&gt; unit&gt; unitId:first”只显示1(第一个匹配的节点)。

提前谢谢。

1 个答案:

答案 0 :(得分:1)

我建议你在xmlmap定义为函数的情况下使用。例如,在您的情况下,您可以使用

xmlmap: function (obj) {
    return $(">units>unit>unitId", obj).map(function() {
               return $(this).text();
           }).get().join("|");
}

请参阅the demo

enter image description here