2012-11-09 49 views
1

这是我的问题:jqGrid的多值列串联选择

我有这样一个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节点的值很好,并且在units集合中看到unitId节点值的所有相应匹配的串联。

所以,我看到类似

Claim Id   Unit Id 

254    123 

我的问题是:我怎么写的单元ID xmlmap的选择,这样的串联产生这样的“1 | 2 | 3”的字符串或“ 1分离器2分离器3“? 我尝试了几件事情,例如,我看到xmlmap:“units> unit> unitId:first”只显示1(第一个匹配的节点)。

预先感谢您。

回答

1

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

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

the demo

enter image description here

+0

奥列格,哥们,我也不蒂娜·特纳,但是,当谈到关于jqGrid的,“你简直是最好的” ! – nenea

+0

@nenea:不客气! – Oleg