Skip to content

Instantly share code, notes, and snippets.

@kimdwkimdw
Forked from SsonHJ/base.js
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimdwkimdw/54d9ca0b741a6cabc37f to your computer and use it in GitHub Desktop.
Save kimdwkimdw/54d9ca0b741a6cabc37f to your computer and use it in GitHub Desktop.
function getArticleAfterArticle(article_id)
{
var EndArticle = false;
$.ajax({
url: "/more",
dataType: 'JSON',
data: {
last_article_id : article_id
},
success: function(data){
if(data.count == 0){
alert("마지막글입니다");
$("#morebtn").hide();
EndArticle =true;
}else{
for (var article_idx in data.article_list)
{
article = data.article_list[article_idx]
string = "<div class='well' id='article_"+ article.id
+"'><h1><a href='/article/detail/"+ article.id +"'>"
+ article.title +"</a></h1><h3>"+ article.author +"</h3><h6>"
+ timeTo(article.date_created)
+"</h6><p> "
+ article.content +" </p> </div>";
$(string).insertAfter($(".well:last"))
}
}
},
error: function(status){
string = "<div class='well' id='article_"+ data.id
+"'><h1>에러가 발생했습니다..</h1></div>";
$("#results").append(string);
}
});
return true;
}
$(document).ready(function() {
var number = 0;
var string;
$('#load_more_button').bind('click', function() {
var article_id = $(".well:last").attr("article_id");
getArticleAfterArticle(article_id);
return false;
});
});
<!-- DOM을 만들때 항상 article_id 를 넣어준다.
$(".well:last").attr("article_id")
로 접근 가능하도록..
-->
<div class="well" id="article_{{ article.id }}" article_id="{{ article.id }}">
@app.route('/', methods=['GET'])
def article_list():
context = {}
rows = max(Article.query.count() - 5, 5)
context['article_list'] = Article.query.order_by(
desc(Article.date_created)).limit(rows)
return render_template('home.html', context=context, active_tab='timeline')
@app.route('/more')
def article_more():
last_article_id = request.args.get('last_article_id', 0, type=int)
article_list = Article.query.filter(Article.id < last_article_id).order_by(
desc(Article.date_created)).limit(5)
article_result = []
for article in article_list:
article_result.append({'id': article.id,
'title': article.title,
'content': article.content,
'author': article.author,
'category': article.category,
'date_created': article.date_created,
})
return jsonify(article_list=article_result, count=article_list.count())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment