↑ 画面不动?没声音?点这里!(教程



全站共计 295.4k 字,自豪地使用 Volantis 主题

博客内容遵循 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 协议

if(isIndex){ var cnt = $(".pageViews").length; var i = 0; var interval = setInterval(function(){ if(i >= cnt) clearInterval(interval); else showPageViewsNum($($(".pageViews")[i++]), AV.Object.extend("Pageview")); },500); }else{ addPageViewsNum($(".pageViews")); } } //仅显示阅读量 function showPageViewsNum(ele, Pageview){ var id = ele.attr('id').trim(); var query = new AV.Query("Pageview"); query.equalTo("post_id", id); query.ascending('createdAt'); query.limit(1); query.find().then(function (results) { $(document.getElementById(id)).text((results && results.length > 0? results[0].get("count") : '0')+"℃"); }, function (error) { $(document.getElementById(id)).text(''); }); } //追加并显示阅读量 function addPageViewsNum(ele){ var id = ele.attr('id').trim(); var title = ele.attr('data-flag-title').trim(); var query = new AV.Query("Pageview"); query.equalTo("post_id", id); query.ascending('createdAt'); query.limit(1); query.find().then(function (results) { if (results.length == 0) { saveNewPageview(id, title); return; } var pageview = results[0]; var count = pageview.get("count"); count++; pageview.set("count", count); pageview.set("title", title); pageview.save().then(function (pageview) { $(document.getElementById(id)).text(count+"℃"); }) }, function (error) { saveNewPageview(id, title); }) } function saveNewPageview(id, title) { var Pageview = AV.Object.extend("Pageview"); var query = new Pageview; query.save({ post_id: id, title: title, count: 1 }).then(function (pageview) { $(document.getElementById(id)).text(pageview.count+"℃"); }, function (error) { }); } if(pageViewsLength){ //此处判断等于 1 在执行 可去除循环 showTime(); } }