我有一个商店网页,我想在用户向下滚动时添加产品块(通过无限滚动)。
我应该使用哪种方法从服务器获取数据并将其添加到 dom?
我看到了这个在angularjs中实现无限滚动的小提琴(当用户到达页面末尾时它运行一个 loadMore() 函数),如上所述,块是商店的产品,每个项目都应该有不同的范围。
问题是我不知道如何在范围内构造数据并通过loadMore()
函数中的 ajax 请求向其中添加更多项目。
我的产品模板:
<section class="more-apps">
<h1>More recommendations</h1>
<div class="loadmore-these">
<!-- ajax requests will load more instances of these three templates -->
<div data-ng-include data-src="'products-template-1.html'"></div>
<div data-ng-include data-src="'products-template-2.html'"></div>
<div data-ng-include data-src="'products-template-3.html'"></div>
</div>
</section>
每个子模板文件都是这样的,有一些简单的区别:
<section data-ng-repeat="i in [1,2,3,4]">
<h1 data-ng-bind-html="title"></h1>
<div data-ng-bind-html="about"></div>
</section>
每个产品在(它自己的?)范围内都有不同title
的about
变量。