问题描述
我有一个angularJS中继器产品。客户希望中继器中每12个产品有一个广告图像,所以我从一个指令开始,然后执行ng-if:@index === 0 ||((@ index + 1)%12 === 0然后触发该指令。然后,该指令决定将添加项相对于重复项放置在何处-在保持列和行流之前或之后。广告相对于产品细分为两列。
页面加载时效果很好。但是,应用过滤器后,一切都会出错。如果过滤器选择了dom中已存在的产品,则该指令不会触发。而且,由于我将其他图像放置在转发器项目之外,因此它们被留在了后面。通过在指令的开头删除所有广告类,很容易做到这一点。
但是,我仍然遇到指令不触发的问题。
我不得不求助于直接的jquery才能使它工作,但这带来了它自己的问题:
$scope.displayAds=function() {
$('.curAd').remove();
var numcols=numCols(); //how many columns are we displaying based on clients window width
for(var i=0;i<$scope.productCount;i++) {
if(i===0||(i+1) % 12===0) {
var slotsThusFar=i+(+$scope.numAds*2)+1 // a slot is one "cell" in our grid,usually a product. But,the ads take two slots.
var newAd=$('.adTemplate').clone();
newAd.removeClass('adTemplate').addClass('curAd');
if (slotsThusFar%numcols!==0||i===0) {
$('[prodindexnum="'+i+'"]').before(newAd);
} else {
$('[prodindexnum="'+i+'"]').after(newAd);
}
newAd.show();
$scope.incrementAddCount();
}
}
}
除了我懒于加载产品图片之外,这工作正常:
<a itemprop="url" href="viewPrd.asp?idproduct={{product.idProduct}}&idcategory=<%=pIdCategory%>" target="_self">
<img class="lazyLoad" itemprop="image" src="/shop/pc/images/lazyLoadPrd.gif" data-src="{{product.smallImageUrl.includes('love') && product.smallImageUrl||'/shop/pc/catalog/'+product.smallImageUrl}}" alt="{{product.description}}">
</a>
在所有广告素材之前,懒惰图像将在页面加载时显示,然后显示正常图像。现在,在我将鼠标移动1像素之前,惰性图像不会更改为正常图像。因此,我必须将其添加到代码中:
$(window).scrollTop($(window).scrollTop()+1); //why do we have to do this? Because our lazyload graphic is still displaying so we have to scroll the dom a pixel
我想我的问题有两个:我如何在带有过滤器的转发器中使用指令,每次应用该过滤器时都会触发该指令,如果不可能,如何解决我的延迟加载问题?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)