70 lines
1.9 KiB
JavaScript
70 lines
1.9 KiB
JavaScript
(function() {
|
|
var status = true;
|
|
var cid = YDUI.util.getQueryString("id") || YDUI.util.getQueryString("key");
|
|
// 如果为 true 表示用户从搜索页面进入 list 列表页面
|
|
// 如果为 false 表示用户从分类页面点击小分类进入 list 列表页面
|
|
|
|
parseInt(cid).toString() == "NaN" ? status = true : status = false;
|
|
|
|
var pns = 0, dat = [];
|
|
|
|
|
|
|
|
function RenderList() {
|
|
$('.g-view').infiniteScroll({
|
|
pageSize: 10,
|
|
initLoad: true,
|
|
loadingHtml: '<strong>加载中...</strong>',
|
|
loadListFn: function () {
|
|
var def = $.Deferred();
|
|
get({
|
|
url: status ? '/query' : '/getClassInfo',
|
|
data: status ? { keyword: cid, pn: pns } : { cid: cid, pn: pns }
|
|
},function(res) {
|
|
var data = res.data;
|
|
data.forEach(function(val) {
|
|
dat.push(val)
|
|
$(".list-theme4").append(`<a class="list-item">
|
|
<div class="list-img">
|
|
<img src="${val.albums[0]}">
|
|
</div>
|
|
<div class="list-mes">
|
|
<h3 class="list-title">${val.title}</h3>
|
|
<div class="list-mes-item">
|
|
<div>
|
|
<p>${val.imtro.substring(0,20)}</p>
|
|
<span >${val.ingredients}</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</a>`);
|
|
def.resolve(res.data);
|
|
|
|
++pns;
|
|
|
|
});
|
|
|
|
|
|
|
|
bindClick(dat)
|
|
})
|
|
|
|
return def.promise();
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
|
|
function bindClick(list) {
|
|
$(".list-theme4 .list-item").on('click',function() {
|
|
var current = list[$(this).index()];
|
|
localStorage.setItem("info",JSON.stringify(current))
|
|
location.href = "./info.html"
|
|
})
|
|
}
|
|
|
|
RenderList()
|
|
|
|
|
|
})() |