首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >填充HTML表列wise

填充HTML表列wise
EN

Stack Overflow用户
提问于 2015-10-16 08:31:28
回答 1查看 4.1K关注 0票数 0

从先前提出的问题来看,他们中的大多数显然对这个问题的回答是否定的。但是,我想应该有一种方法,我可以填充HTML表所需的方式。

我有一个HTML表,可以使它按行填充,但我希望消除所显示的属性名称的重复。

我有在逐行填充和结果输出中工作的代码。我尝试过同样的列智慧,但我看不出我可以在哪里填充这些值。

表中的值是从数据库中填充的。

按行填充表的代码。

代码语言:javascript
复制
<table class="table">
    <tr>
        <th>Delete</th>
        <th>Option Value</th>
        <th colspan="3">Set Value</th>
        @*<th></th>
        <th></th>
        <th></th>*@
    </tr>
    @foreach (var item in Model.OptionValues)
    {
        //var row = @item.SetValue.Count + 1;
        if (item.SetValue.Count == 0)
        {   @:<tr>
            @:<td>@Html.ActionLink("Delete", "Delete", "Optionvalues", new { id = item.OptionValueID},null)</td>
            @:<td>@item.OptionVal</td>
            @:<td></td>
            @:</tr> 
    }
        int count = 0;
    if(item.SetValue.Count!=0)
    {
        @:<tr>
            @:<td rowspan="@item.SetValue.Count">@Html.ActionLink("Delete", "Delete", "Optionvalues", new { id = item.OptionValueID},null)</td>
            @:<td rowspan="@item.SetValue.Count">@item.OptionVal</td>

            foreach(var set in item.SetValue)
            {
                if (count ==0)
                {
                @:<td>@set.TcSet.SetName</td>
                @:<td>@set.Value</td>
                @:<td>@set.Status</td>
                @:<td>@Html.ActionLink("Edit", "Edit", "SetValues", new { id = set.SetValueID },null)</td>
                @:</tr>
                }
                else
                {
                    @:<tr>
                    @:<td>@set.TcSet.SetName</td>
                    @:<td> @set.Value</td>
                    @:<td>@set.Status</td>
                    @:<td>@Html.ActionLink("Edit", "Edit", "SetValues", new { id = set.SetValueID },null)</td>
                }
                count++;

            }
            }
         @:</tr>
    } 
</table>

结果表的输出

预期输出

我可以用属性名填充第一列。但我不知道如何在下一篇专栏中填充这些值。

我尝试了一个foreach循环,但是我无法按列填充值。

手头的任务还有工作要做吗?

更新

根据“Nick”的建议,我尝试了以下方法

代码语言:javascript
复制
 @foreach(var ov in Model.OptionValues)
 {
 <div class="col">@ov.OptionVal</div>
 foreach(var s in ov.SetValue)
 {
    <div class="row">@s.Value</div>
 }
 }
EN

回答 1

Stack Overflow用户

发布于 2015-10-16 08:47:45

你必须使用表格布局吗?您可以简单地使用块元素,并将它们与css列或css flex框对齐;

所以:

代码语言:javascript
复制
`@foreach (var i in Model)
    {
div.column
 @foreach (var set in i)
    {
   div.row-in-col
    } 
}` 

然后在css中

代码语言:javascript
复制
`.element-that-contains-columns{
 display:flex;
}
.row-in-col {
height : @some-fixed-height;
}`

会产生这样的结果:

代码语言:javascript
复制
.container{display:flex}
.row{
  height:30px;
  padding:4px
}
代码语言:javascript
复制
<div class="container">
	<div class="col">
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
	</div>
	<div class="col">
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
	</div>
	<div class="col">
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
	</div>
	<div class="col">
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
	</div>
	<div class="col">
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
	</div>
	<div class="col">
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
		<div class="row">Lorem</div>
	</div>
</div>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33165847

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档