java使用javascript呈现的2个列表
我正在我的web应用程序中创建一个tagCloud。我有一个方法可以呈现两个列表:
public static void tagCloud(){
List<Topic> topics = Topic.find("order by topicName asc").fetch();
List<Tutorial> tutorials = Tutorial.find("order by id asc").fetch();
List<Integer> topicCount = new ArrayList<Integer>();
for(int i = 0; i < topics.size(); i++){
int z = 0;
for(int j = 0; j < tutorials.size(); j++){
if (tutorials.get(j).getTopic().equals(topics.get(i))){
z++;
topicCount.add(z);
}
}
}
render (topics, topicCount);
}
我想用这两个列表作为tagCloud的一行,类似于这一行:
<a href="/Topics/topicView?topicId=${topicList.id}" rel="8">${topicList.topicName.raw()}</a>
我想使用topicCount列表中的索引作为“rel”(单词的大小),主题作为要显示的元素本身,我该怎么做
# 1 楼答案
我不会有两个列表,而是将每个主题及其计数存储在单个对象中(我们称之为
TopicWithCount
),并使用单个List<TopicWithCount>