0

我正在尝试使用 Big Cartel Javascript api 来检索分页的产品数组。例子:

Product.findAll({
  category: 'jewelry',
  page: 2,
  limit: 3
}, function(myProducts) {
  console.log("Found " + myProducts.length);
});

无论参数如何,该函数始终返回一个包含商店中所有产品的数组。

谢谢你的帮助,凯文

4

1 回答 1

1

我一直想联系 Big Cartel 支持,因为我遇到了同样的问题。如果您想要一个不太好的解决方法,您可以使用以下代码。createPortfolio 是我用来创建图像网格的一个单独的插件。

(function ($) {       
$(document).ready(function(){
    var categoryItems = [];
    var mainItemName = "{{page.name}}";

        Product.findAll({}, function(products) { 
            var lastItem = products.length - 1;
            $.each(products, function(i, product) {
                var productItem = {
                    itemText: product.name,
                    itemPrice: product.price,
                    imageLink: product.images[0].url,
                    secondaryImages: [product.url],
                    externalLink: true
                };  
                if(product.categories[0]) {
                    for(j = 0; j < product.categories.length; j++) {
                        if(product.categories[j].name === mainItemName) {
                            categoryItems.push(productItem);
                        }
                    };
                }

                if(i === lastItem ) {
                    $('.portfolio_page').createPortfolio({
                          imagesPerRow: 3,
                          gridType: 'masonry',
                          captionType: 'static',
                          imagesPerPage: 8,
                          paginationPosition: 'scroll',
                          imageWidth: 1000,
                          imageHeight: 1000,
                          enablePopupInfo: true,  
                          portfolioItems: categoryItems
                    });                            
                }

            }); 
        });
});    
})(jQuery);   
于 2015-06-26T17:33:50.790 回答