-
-
Save kimdwkimdw/54d9ca0b741a6cabc37f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- DOM을 만들때 항상 article_id 를 넣어준다. | |
$(".well:last").attr("article_id") | |
로 접근 가능하도록.. | |
--> | |
<div class="well" id="article_{{ article.id }}" article_id="{{ article.id }}"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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