我正在我的网络应用程序中创建一个 tagCloud。我有一个呈现 2 个列表的方法:
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);
}
我想在与此类似的一行中使用这 2 个列表作为 tagCloud:
<a href="/Topics/topicView?topicId=${topicList.id}" rel="8">${topicList.topicName.raw()}</a>
我想使用 topicCount 列表中的索引作为“rel”(单词的大小),主题作为要显示的元素本身,我该怎么做?
最佳答案
我不会使用两个列表,而是将每个主题及其计数存储在单个对象中(我们称之为 TopicWithCount
),并使用单个 List<TopicWithCount>
。 .
关于java - 使用 2 个在 javascript 中呈现的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10664811/