Javascript Shopify';查看所有';按钮实现
Shopify每页最多显示50种产品 为了绕过这个限制,我制作了一个jquery代码片段。该脚本从每个分页链接获取url,并执行ajax加载—将结果添加到主内容区域 这对我来说非常有效,但对我的朋友来说却不行。他每次都缺一页。所以我认为这可能是一个异步问题,因为他的连接比我的慢。所以我重写了几次脚本,使其更加明确。但这对他还是不起作用 经过多次故障排除,如果以管理员身份登录,似乎一切正常。如果未登录,则中间页面无法加载 以下是我最近的代码:Javascript Shopify';查看所有';按钮实现,javascript,jquery,shopify,Javascript,Jquery,Shopify,Shopify每页最多显示50种产品 为了绕过这个限制,我制作了一个jquery代码片段。该脚本从每个分页链接获取url,并执行ajax加载—将结果添加到主内容区域 这对我来说非常有效,但对我的朋友来说却不行。他每次都缺一页。所以我认为这可能是一个异步问题,因为他的连接比我的慢。所以我重写了几次脚本,使其更加明确。但这对他还是不起作用 经过多次故障排除,如果以管理员身份登录,似乎一切正常。如果未登录,则中间页面无法加载 以下是我最近的代码: {% if template contains 'co
{% if template contains 'collection' %}
<script>
$(document).ready(function() {
$('#viewFewerProducts').hide();
// when viewAllProducts is clicked
$("#viewAllProducts").click( function (e) {
e.preventDefault();
$("#viewAllProducts , #paginationMagic").hide(); // hide pagination buttons
// and clear out collectionThumbs - but add the ViewAllRow back in.
$("#collectionThumbs").empty().html('<div class="row" id="viewAllRow"></div>');
// see how many pagination links there are. Add 1 because of index 0
var numberOfPages = $('#paginateNumbers .item').length + 1
var path = window.location.pathname;
var pageURL;
// this bit adapted from blog post... but cant remember url
for (var i=1;i<numberOfPages;i++) {
$.ajax(
{
type: 'GET',
url: pageURL = path + "?page=" + i, // build pagination page url
ajaxI: i, // Capture the current value of 'i'.
success: function(data)
{
i = this.ajaxI; // Reinstate the correct value for 'i'.
$(data).find('#collectionThumbs').each(function()
{
// Read data... and stick it in the page
var importedCollection = $(data).find("#collectionThumbs a").unwrap();
importedCollection.appendTo("#viewAllRow");
});
},
error: function(data)
{
// Handle errors here.
}
});
}
///
$("#viewFewerProducts").show();
});
// reload the window
$("#viewFewerProducts").click( function (e) {
e.preventDefault();
$("#viewFewerProducts").text('loading...').removeAttr('id');
location.reload();
});
});
</script>
{% endif %}
{%if模板包含“集合”}
$(文档).ready(函数(){
$(“#viewFewerProducts”).hide();
//单击viewAllProducts时
$(“#查看所有产品”)。单击(功能(e){
e、 预防默认值();
$(“#viewAllProducts,#paginationMagic”).hide();//隐藏分页按钮
//并清除collectionThumbs-但将ViewAllRow添加回。
$(“#collectionThumbs”).empty().html(“”);
//查看有多少分页链接。由于索引0,请添加1
var numberOfPages=$('#paginateNumbers.item')。长度+1
var path=window.location.pathname;
var-pageURL;
//这一点改编自博客文章…但我记不起url
对于(var i=1;既然可以使用Liquid对任何集合进行分页,为什么要使用这种方法而不仅仅是分页呢?如果你想展示每页100个产品,而你有1000个产品,那么你将有10个页面需要处理,没有XHR的废话需要处理。嗨,David,我使用Liquid进行分页-ajax调用会命中这些分页了解从哪个页面提取html的链接…Shopify是否已提高其api限制?是否已进行编辑/更新。如何标记它已解决?是否已检查是否使用不同登录名从Ajax请求获取数据?
{% if template contains 'collection' %}
<script>
$(document).ready(function() {
$('#viewFewerProducts').hide();
$("#viewAllProducts").click( function (e) {
e.preventDefault();
$("#viewAllProducts , #paginationMagic").hide();
var numberOfPages = $('#paginateNumbers .item').length + 1
var path = window.location.pathname;
// console.log(path);
var pageURL;
//
for (var i=1;i<numberOfPages;i++) {
// console.log(i + 'a')
$.ajax(
{
type: 'GET',
url: pageURL = path + "?page=" + i,
beforeSend: function() {
$("#collectionThumbs").empty();
},
ajaxI: i, // Capture the current value of 'i'.
success: function(data)
{
i = this.ajaxI; // Reinstate the correct value for 'i'.
$(data).find('#collectionThumbs').each(function() {
// Read data from XML...
$('<div class="row" id="viewAllRow' + i + '"></div>').appendTo("#collectionThumbs");
var importedCollection = $(data).find("#collectionThumbs a").unwrap();
importedCollection.appendTo("#viewAllRow" + i );
// alert("now showing " + ($("#viewAllRow" + i + " a").length) + " products" );
});
var numberOfRows = $('#collectionThumbs .row').length + 1
var viewAllRowItem = []
for (var x=1;x<numberOfRows;x++) {
//put each row into a variable
viewAllRowItem[x] = $("#viewAllRow" + x ).clone();
$("#viewAllRow" + x ).remove();
// console.log(viewAllRowItem[x])
}
for (var x=1;x<numberOfRows;x++) {
$(viewAllRowItem[x]).appendTo('#collectionThumbs');
}
},
dataType: "html",
error: function(data)
{
// Handle errors here.
}
});
}
$("#viewFewerProducts").show();
});
$("#viewFewerProducts").click( function (e) {
e.preventDefault();
$("#viewFewerProducts").text('loading...').removeAttr('id');
location.reload();
});
});
</script>
{% endif %}