使用 OGNl 表达式进行条件显示
在我的struts项目中,我在数组列表中有一组记录,这些记录有它的名称和类别ID。在第二个数组列表中,我有类别记录(category_id,categoryname)。
现在我想列出第一个列表,其中类别名称作为副标题,就像
ArrayList1:(nameDetailList)
NAME: CATEGORYID
name1 1
name2 2
name3 1
name4 5
ArrayList2:(categoryList)
CategoryID CategoryName
1 Category-1
2 Category-2
3 Category-3
4 Category-4
5 Category-5
我需要将它们显示为
Category-1
--name1
--name3
Category-2
--name2
Category-5
--name3
“注意:这里我不想显示没有与之关联的记录的类别名称”。为此我在下面编写了代码。
<s:iterator id="catIter" value="categoryList">
<s:property value="categoryName"/>
<s:iterator value="nameDetailList.{ ?this.categoryId==#catIter.categoryId}">
<s:property value="Name"/>
</s:iterator>
</s:iterator>
它还显示没有与这些记录关联的类别。任何人都可以告诉如何控制类别名称的显示。 或者有其他更好的选择吗?
In My struts project i have set of records in an array list,these recors have its name and categoryid. and in second arraylist i have records for category(category_id, categoryname).
now i want to list the first list with the category name as subheadings like
ArrayList1:(nameDetailList)
NAME: CATEGORYID
name1 1
name2 2
name3 1
name4 5
ArrayList2:(categoryList)
CategoryID CategoryName
1 Category-1
2 Category-2
3 Category-3
4 Category-4
5 Category-5
I need these to be displayed as
Category-1
--name1
--name3
Category-2
--name2
Category-5
--name3
Note: Here i don't want to display the category names that don't have records associated for that. for this i coded below.
<s:iterator id="catIter" value="categoryList">
<s:property value="categoryName"/>
<s:iterator value="nameDetailList.{ ?this.categoryId==#catIter.categoryId}">
<s:property value="Name"/>
</s:iterator>
</s:iterator>
it displaying the categories those don't have records asssociated with those also.can anyone tell how to control the display of category name.
or is there any other better alternatives for this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过计算与类别相关的 nameDetail 数量来完成此操作。如果一个类别没有任何相关的 nameDetail ,它不会打印它的名称。
如果您有一个按categoryId 返回nameDetails 的方法,则无需任何计数即可完成。不知道您的情况是否有更好的解决方案。
You can do it by counting the number of nameDetail that is related to category. If a category does not have any nameDetail related, it is not gonna print its name.
If you have a method that returns the nameDetails by categoryId, you can do it without any count. I don't know if there is a better solution for your case.
我已将代码更新为
现在我得到了所需的输出。但解决方案是最好的吗?
i have updated my codes to
Now i'm getting the desired output. but is solution is the best one??