2015-02-24 52 views
0

我是新百里香。我被困在一个地方,我需要遍历另一个列表中存在的字符串列表。例如,我有这样的json:如何遍历thymeleaf中另一个列表中的列表?

{ 
     "_id" : ObjectId("54e1865423asgj086"), 
     "Name" : "Carbon Utility", 
     "Modified In " : "DEC 5th", 
     "Imported" : "N", 
     "Classification" : "Functional SW delivery", 
     "Type Designation" : "Heavy Use", 
     "StateList" : [ 
       { 
         "name" : "Create", 
         "currentStatus" : "False", 
         "stateDuration" : "336264  " 
       }, 
       { 
         "name" : "Implement", 
         "currentStatus" : "False", 
         "stateDuration" : "1393827  " 
       }, 
       { 
         "name" : "RampUp", 
         "currentStatus" : "False", 
         "stateDuration" : "34  " 
       }, 
       ] 
       } 

在我的控制器中,我将它添加到一个对象。

@RequestMapping(value = "/Search1", method = RequestMethod.GET) 
    public String showEntity(@RequestParam("type") String typeNameid,Model model,HttpSession session) { 
     ------ my other stuffs-------- 
     ---- here i'm getting data from other html and spliting to add to model---- 
     model.addAttribute("resultSourceDbObject",migrationSourceDataBean.getResultSourceDbObject()); 

     return "wipdm/Display"; 
    } 

现在,在我的html页面。我可以打印ID,名称和类型的设置。但我坚持迭代通过状态列表。对于每个状态列表,我必须在表格内创建一个单独的子文件夹,并且需要显示名称,状态和持续时间。我正在尝试这个,但没有工作。

<table id="example-advanced" class="table table-striped table-bordered table-hover" style=" font-size:1.1em;"> 
     <thead class="dark-border-bottom"> 
      <tr> 
       <th style="text-align:center"> Key</th> 
       <th style="text-align:center">Values</th> 
      </tr> 
     </thead> 
     <tbody> 
      <tr data-tt-id='1'><td><span class="file">&nbsp;&nbsp;Type</span></td><td><span th:text="${resultSourceDbObject.getString('Type Designation')}"></span> </td></tr> 
      <tr data-tt-id='1'><td><span class="file">&nbsp;&nbsp;Name</span></td><td><span th:text="${resultSourceDbObject.getString('Name')}"></span> </td></tr> 
      <tr data-tt-id='1'><td><span class="file">&nbsp;&nbsp;id</span></td><td><span th:text="${resultSourceDbObject.getString('_id')}"></span> </td></tr> 
      <tr data-tt-id='2'><td><span class='folder'>Statelist</span></td><td></td></tr> 
       <tr data-tt-id='2-1' data-tt-parent-id='2' th:each="relresult : ${resultSourceDbObject.getString('StateList')}"><td><span class='folder' th:text="Relationship" >Relationship</span></td><td>Folder</td></tr> 
       <tr data-tt-id='2-1-1' data-tt-parent-id='2-1'><td><span class='file' >name</span></td><td th:text="${relresult.getString('name')}">Release</td></tr> 
       <tr data-tt-id='2-1-2' data-tt-parent-id='2-1'><td><span class='file'>currentstatus</span></td><td th:text="${relresult.getString('currentStatus')}">132456424</td></tr> 
       <tr data-tt-id='2-1-3' data-tt-parent-id='2-1'><td><span class='file'>Stateduration</span></td><td th:text="${relresult.getString('stateDuration')}">16572464</td></tr> 
     </tbody> 
</table> 

有人可以告诉我我哪里会出错,如何实现这一目标。提前致谢。

+0

'migrationSourceDataBean.getResultSourceDbObject()'返回什么样的对象?你能分享课堂堕落吗? – lgd 2015-02-24 08:54:56

+0

它只是json对象。 'th:text =“$ {resultSourceDbObject.getString('Type Designation')}”'这给了我Type的期望输出。我的问题是迭代状态列表。 – Crazy2crack 2015-02-25 05:37:40

回答

0

我不确定哪种物体migrationSourceDataBean.getResultSourceDbObject()正在返回,但resultSourceDbObject.getString('StateList')不会返回您所需要的。 (我想这只是给你的JSON?)

假设它类似于JSONObject你应该打电话给getJSONArray()(或类似),它会给你你可以迭代的嵌套列表。