逻辑循环Thorugh菜单 [英] Logic In Looping Thorugh Menu
问题描述
我的逻辑有点困难,想知道是否有人可以提供帮助.
基本上我有一个如下的订单清单:
< ul>
< li>第一项</li>
< li>第二项</li>
< li>项目3</li>
< li>项目4</li>
</ul>
< ul>
< li>项目5</li>
< li>第六项</li>
< li>项目7</li>
< li>项目8</li>
</ul>
我要遍历数据表并在构建过程中建立一个字符串.见下文
对于i = 0到dt.rows.count-1
如果我的mod 3 = 0,那么
str_val + =< ul>"
如果结束
str_val + =< li>项目一</li>"
如果我mod 3 0那么
str_val + =</ul>"
如果结束
下一个
我遇到的问题是在第一组迭代之后,它关闭了有序列表,但随后又没有再次打开它.
有人有类似的问题吗?如果是这样,将不胜感激.
问候
McGann
I am having a bit of difficulty in my logic and was wondering if anyone could help.
Basically I have an order list like below:
<ul>
<li>Item One</li>
<li>Item Two</li>
<li>Item Three</li>
<li>Item Four</li>
</ul>
<ul>
<li>Item Five</li>
<li>Item Six</li>
<li>Item Seven</li>
<li>Item Eight</li>
</ul>
I am iterate through a datatable and building up a string as I go. See Below
For i = 0 to dt.rows.count - 1
If i mod 3 = 0 then
str_val +="<ul>"
End If
str_val +="<li>Item One</li>"
If i mod 3 0 then
str_val +="</ul>"
End If
Next
The problem I am having is after the first group of iterations it closes the ordered list but then doesn''t open it again.
Has anyone had a similiar problem? If so any help is much appreciated.
Regards
McGann
推荐答案
当然会.
在循环开始时,您的i = 0
i mod 3 = 0-您打开< ul>
然后添加一个元素
并关闭< ul>标签在同一迭代中.
对于下一次迭代,您有i = 1
我mod 3 = 1,它既不打开也不关闭.
可能的解决方案如下所示:
Of course it will.
At start your loop you have i = 0
i mod 3 = 0 - you open <ul>
then add an element
and closed <ul> tag inside same iteration.
for next iteration you have i = 1
i mod 3 = 1 and it neither opens nor closes.
possible solution may look like this:
For i = 0 to dt.rows.count - 1
If i mod 3 = 2 then ' 2 is because it actually is 3 -1
str_val +="</ul>"
End If
If i mod 3 = 0 then
str_val +="<ul>"
End If
str_val +="<li>Item One</li>"
If i mod 3 0 then
str_val +="</ul>"
End If
Next
if dt.rows.count > 0 then
str_val +="</ul>"
end if
顺便说一句,为什么要使用3,如果您要在一个组中有4个项目,则应该使用4(在关闭标签的第一个检查中为3).
By the way why are you using 3, if you want to have 4 items in a group you should use 4 (and 3 in the first check which closes the tag).
这篇关于逻辑循环Thorugh菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!