我正在創建一個簡單的博客Web應用程序使用播放框架,其中有某些類別和用戶可以發佈到他們想要的類別,但問題是,當我發佈到一個類別該帖子也發佈到所有類別。使用播放框架的博客Web應用程序的邏輯錯誤
Application code:
import java.util.*;
import models.*;
public class Application extends Controller {
public static void index() {
List Posts = Post.find ("order by type desc").fetch();
render(Posts);
}
public static void addpost (String content) {
Post post = new Post(content).save();
renderJSON(content);
html code:
<h2>
CollabBlog
</h2>
#{extends 'main.html' /}
#{set title:'Home' /}
<head>
<title>#{get 'title' /}</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css" media="screen"
href="@{'/public/stylesheets/categories.css'}" />
</head>
<h3>Category: Health</h3>
#{ifnot Posts}
No posts to view
#{/ifnot}
<ul>
#{list items:Posts, as: 'Post'}
<li>
<p>${Post.poster}</p><p>${Post.content}</p>
</li>
#{/list}
</ul>
<p>
<a id="addpost" href="#">add new Health's post</a>
</p>
<h3>Category: Politics</h3>
#{ifnot Posts}
No posts to view
#{/ifnot}
<ul>
#{list items:Posts, as: 'Post'}
<li>
<p>${Post.poster}:</p><p>${Post.content}</p>
</li>
#{/list}
</ul>
<p>
<a id="addpost" href="#">add new Politic's post</a>
</p>
<h3>Category: Entertainment</h3>
#{ifnot Posts}
No posts to view
#{/ifnot}
<ul>
#{list items:Posts, as: 'Post'}
<li>
<p>${Post.poster}</p><p>${Post.content}</p>
</li>
#{/list}
</ul>
<p>
<a id="addpost" href="#">add new Entertainment's post</a>
</p>
<body>
<link href="index.css" rel="stylesheet" type="text/css">
</body>
<script type="text/javascript" charset="utf-8">
$('#addpost').click(function() {
$.post('@{addpost()}', {content: prompt('post content ?')}, function(Post){
$('ul').prepend()
})
$.post('@{addpost()}', {poster : prompt('which category ?')}, function(Post){
$('ul').prepend()
})
})
</script>
}
}
有誰知道如何解決這個問題?
帖子如何與類別鏈接? – digiarnie 2012-03-08 23:21:50
實際上他們沒有鏈接,用戶決定添加帖子到他想要的類別。 – 2012-03-08 23:28:29
在您的三個類別中,您可以使用相同的項目(帖子)撥打#{list}。這些類別如何區分這些帖子? – digiarnie 2012-03-09 01:22:48