未在预期位置显示的无序列表项目符号

约翰

我有以下代码工作正常,我根据 JSON 响应显示信息(将其转换为数组后)。谁能告诉我我在代码片段下面的屏幕截图中提到的格式是否可以实现?现在,标题First Description为与其关联的每个列表项重复。同样是这种情况Second Description

var data_ = {
   "webservice_status":{
      "status":"SUCCESS",
      "message":""
   },
   "tableData":[
      {
        
         "type_id":553,
         "catDesc":"First Description",
         "myDataDesc":"First unordered list element of first description",
         "toolTip":"First unordered list element of first description"
        
      },
      {
        
         "type_id":554,
         "catDesc":"First Description",
         "myDataDesc":"Second unordered list element of first description",         
         "toolTip":"Second unordered list element of first description"
        
      },
      {
        
         "type_id":220,
         "catDesc":"Second Description",
         "myDataDesc":"First unordered list element of second description",
         "toolTip":"First unordered list element of second description"
         
      },
      {
        
         "type_id":201,
         "catDesc":"Second Description",
         "myDataDesc":"Second unordered list element of second description",
         "toolTip":"Second unordered list element of second description"
         
      },
      {
        
         "type_id":202,
         "catDesc":"Second Description",
         "myDataDesc":"3rd unordered list element of second description",
         "toolTip":"3rd unordered list element of second description"
         
      },
      {
        
         "type_id":255,
         "catDesc":"Second Description",
         "myDataDesc":"4th unordered list element of second description",
         "toolTip":"4th unordered list element of second description"
         
      },
      {
        
         "type_id":250,
         "catDesc":"Second Description",
         "myDataDesc":"5th unordered list element of second description",
         "toolTip":"5th unordered list element of second description"
         
      },
      {
        
         "type_id":300,
         "catDesc":"Third Description",
         "myDataDesc":"1st unordered list element of third description",
         "toolTip":"1st unordered list element of third description"
         
      },
      {
        
         "type_id":1,
         "catDesc":"Fourth Description",
         "myDataDesc":"1st unordered list element of 4th description",
         "toolTip":"1st unordered list element of 4th description"
         
      }
      
   ]
}


var json = data_.tableData;
const data = json.reduce((result, current) => {
              const entry = result.find(({ catDesc }) => current.catDesc === catDesc)
              const { catDesc, myDataDesc,toolTip } = current
                          
                if (entry) {
                entry.myDataDesc.push(myDataDesc);
                entry.toolTip.push(toolTip);
                
                
              } else {
                result.push({ catDesc, myDataDesc: [myDataDesc],toolTip:[toolTip] })
              }

              return result
            }, [])   
            
console.log(data);  

 for (var i = 0; i < data.length; i++) {
 for (var j = 0; j < data[i].myDataDesc.length; j++) {
$('#populateTable')
  .append('<tr height="30"><td width="33%" align="left"><u><b>'+data[i].catDesc+'</b></u><br></td></tr><tr height="5px"></tr><tr><td title="'+data[i].toolTip+'" width="33%" style="padding-left:40px;"><ul style="list-style-type:  disc"><li>'+data[i].myDataDesc[j]+'  </li><ul></td><td width="33%" align="left"><img src="images/DownloadImage.jfif" title="Download" alt="Download" width="20" height="20"></td></tr>');
  
  }
  }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
   <tbody id="populateTable">
       </tbody>
</table>

但它没有以以下所需的格式显示它。

在此处输入图片说明

在此处输入图片说明

范范

这就是我想出的。

var outputtable = "";
for (var i = 0; i < data.length; i++) {
  var header = "";
  header += '<tr height="30"><td width="33%" align="left"><u><b>' + data[i].catDesc + '</b></u><br></td></tr><tr height="5px"></tr>';
  var contents = "";
  for (var j = 0; j < data[i].myDataDesc.length; j++) {
    contents += '<tr><td title="' + data[i].toolTip + 
    '" width="33%" style="padding-left:40px;"><ul style="list-style-type:  disc"><li>' + data[i].myDataDesc[j] + '  </li>';
    contents += '<ul></td><td width="33%" align="left"><img src="images/DownloadImage.jfif" title="Download" alt="Download" width="20" height="20"></td></tr>';
  }
  outputtable += header + contents
}
$('#populateTable').append(outputtable);

您的原始代码为每个 i 的每个 j 附加标题和行。我发布的这段代码使用一个contents变量来收集单个标题下每一行的 HTML。

我希望这个答案对你有用。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

无序列表-列表项位置

来自分类Dev

Reportlab无序列表未显示项目符号

来自分类Dev

display:table时显示无序列表的项目符号

来自分类Dev

第一个列表项之后带有项目符号的无序列表

来自分类Dev

第一个列表项之后的带项目符号的无序列表

来自分类Dev

用于在多个图像之间循环以装饰无序列表项目符号的 CSS

来自分类Dev

如何仅使用嵌入式CSS(用于电子邮件)自定义无序列表项目符号?

来自分类Dev

无序列表jquery在固定位置显示了从列表中选择的项目

来自分类Dev

排列无序列表项

来自分类Dev

列表中未包含无序列表中的项目符号?

来自分类Dev

列表中未包含无序列表中的项目符号?

来自分类Dev

未在无序列表中显示 json 解析数据

来自分类Dev

无序列表中项目符号之前的文本

来自分类Dev

无序列表和动态项目符号图像

来自分类Dev

删除开关的无序列表中的项目符号

来自分类Dev

从无序列表中删除项目符号

来自分类Dev

列表项的无序列表数

来自分类Dev

替换无序列表中的列表项

来自分类Dev

css masonry 无序列表项

来自分类Dev

<ul>列表项目符号显示在一个位置,但不在另一个位置

来自分类Dev

子级别列表项目符号的奇怪位置

来自分类Dev

如何微调列表项目符号/编号的位置

来自分类Dev

jQuery仅显示多个无序列表中的5个列表项

来自分类Dev

如何使用jquery(最好)显示和隐藏无序列表(ul)中的列表项(li)元素?

来自分类Dev

我可以分别设置不同的无序列表项目的样式吗?

来自分类Dev

jQuery-多步骤表单进度栏,使用无序列表项显示完成的步骤

来自分类Dev

CSS-无序列表中项目符号之间的垂直线

来自分类Dev

如何在UITextView中的每一行添加无序列表或项目符号

来自分类Dev

使用 NSHTMLTextDocumentType 属性的 UITextView 中具有无序列表的重复项目符号

Related 相关文章

  1. 1

    无序列表-列表项位置

  2. 2

    Reportlab无序列表未显示项目符号

  3. 3

    display:table时显示无序列表的项目符号

  4. 4

    第一个列表项之后带有项目符号的无序列表

  5. 5

    第一个列表项之后的带项目符号的无序列表

  6. 6

    用于在多个图像之间循环以装饰无序列表项目符号的 CSS

  7. 7

    如何仅使用嵌入式CSS(用于电子邮件)自定义无序列表项目符号?

  8. 8

    无序列表jquery在固定位置显示了从列表中选择的项目

  9. 9

    排列无序列表项

  10. 10

    列表中未包含无序列表中的项目符号?

  11. 11

    列表中未包含无序列表中的项目符号?

  12. 12

    未在无序列表中显示 json 解析数据

  13. 13

    无序列表中项目符号之前的文本

  14. 14

    无序列表和动态项目符号图像

  15. 15

    删除开关的无序列表中的项目符号

  16. 16

    从无序列表中删除项目符号

  17. 17

    列表项的无序列表数

  18. 18

    替换无序列表中的列表项

  19. 19

    css masonry 无序列表项

  20. 20

    <ul>列表项目符号显示在一个位置,但不在另一个位置

  21. 21

    子级别列表项目符号的奇怪位置

  22. 22

    如何微调列表项目符号/编号的位置

  23. 23

    jQuery仅显示多个无序列表中的5个列表项

  24. 24

    如何使用jquery(最好)显示和隐藏无序列表(ul)中的列表项(li)元素?

  25. 25

    我可以分别设置不同的无序列表项目的样式吗?

  26. 26

    jQuery-多步骤表单进度栏,使用无序列表项显示完成的步骤

  27. 27

    CSS-无序列表中项目符号之间的垂直线

  28. 28

    如何在UITextView中的每一行添加无序列表或项目符号

  29. 29

    使用 NSHTMLTextDocumentType 属性的 UITextView 中具有无序列表的重复项目符号

热门标签

归档