使用播放!1.2.3
我试图在一个页面中呈现一个表格,最初的 ArrayList 包含 100 个帖子。这工作正常。然后,使用 ajax 请求,我想将 100 个帖子附加到该 ArrayList 并使用新的 ArrayList 呈现页面。
我的问题是,在将 100 个帖子附加到初始 ArrayList 后,页面不会使用更新的列表呈现。任何人都可以对此有所了解吗?我的代码如下
//method to render the users home page
public static void home(String username) throws IllegalArgumentException, IOException, FeedException, MongoException, TasteException, InterruptedException
{
if(validateUser() != null && validateUser().equals(username))
{
RSSReader reader = RSSReader.getInstance(username);
List<Posts> mainFeed = new ArrayList<Posts>();
List<Posts> recommendedFeed = reader.getRecommendedFeed();
Map<String, Object> args = new HashMap<String, Object>();
if(request.isAjax())
{
mainFeed = reader.updateMainFeed();
for(int i = 0; i < mainFeed.size(); i++)
{
System.out.println("feed item: " + i + " " + mainFeed.get(i));
}
System.out.println("Main feed size: " + mainFeed.size());
renderArgs.put("mainFeed", mainFeed);
renderArgs.put("recommendedFeed", recommendedFeed);
renderArgs.put("username", username);
//render(mainFeed, recommendedFeed, username);
}
else if(!request.isAjax())
{
mainFeed = reader.getMainFeed();
renderArgs.put("mainFeed", mainFeed);
renderArgs.put("recommendedFeed", recommendedFeed);
renderArgs.put("username", username);
System.out.println("Main feed size: " + mainFeed.size());
}
render();
}
else
{
loginScreen();
}
}
该表的html是:
#{if mainFeed.size() > 1}
<div class="span9">
<div class="well">
<h4>Articles</h4>
<table class="table table-bordered" style="max-width: 829.7916870117188px">
<tbody>
#{list items:mainFeed, as:'article'}
<tr style="max-width: 829.7916870117188px">
<td><b>${article.title}</b>
<span class="twit" style="float:right; padding-left:10px">
<a href="https://twitter.com/share" class="twitter-share-button"
data-url="${article.link}"
data-dnt="true">Tweet</a>
</span>
<span class="share-widget" style="float:right"><fb:like
href=${article.link} send="false" layout="button_count"
width="100" show_faces="false" font="segoe ui"
action="recommend"></fb:like>
</span>
</br>
<p style="max-width: 810px;">${article.description}</p> </br>
<a href=${article.link} target="_blank">Read more...</a>
<p style="float: right">
<b>${article.source}</b>
</p></td>
</tr>
#{/list}
</tbody>
</table>
<button class="btn-small btn-primary"
type="submit"
onclick="loadMore();" style=" display: block; margin-left:
auto;margin-right:auto ">Load more articles
</button>
</div>
</div>
#{/if}
ajax 请求的代码是:
//function to append next 100 posts to list
function loadMore()
{
//call $.ajax here
$.ajax({
url: "/home",
type: 'GET',
});
}