Exploring Ionic Lists

Infinite Lists

由于手机不适合使用多页面显示posts,Infinite Lists成为各种新闻、咨询类app的标配。为了在ionic框架中使用到Infinite Lists,我们首先学习ion-list。

ion-list

ion-list使用

在ionic中,通过使用ion-list和ion-item来展示数据,通过ng-repeat循环输出,如demo(使用ionic start mydemo tabs命令生成ionic demo)中的templates/tab-friends.html中显示:

    <ion-list>
      <ion-item ng-repeat="friend in friends" type="item-text-wrap" href="#/tab/friend/{{friend.id}}">
        {{friend.name}}
      </ion-item>
    </ion-list>

假如我们返回到html的数据,每次都为20项,则但屏幕划到最后一项或前几项时,则需要监听检测到,并且载入下一个20项数据,从而达到无止境的下滑刷新载入更多的目标。这里,ionic提供了ion-infinite-scroll directive。

ion-infinite-scroll function is more like a scroll detector: it detects when a user is scrolled to a given point above the bottom of the view (default 1%, or 99% of the way down), and executes a function.

所以需要在html中添加这个directive,如下:

    <ion-list>
        <ion-item ng-repeat="friend in friends" type="item-text-wrap" href="#/tab/friend/{{friend.id}}">
            {{friend.name}}
        </ion-item>
        <ion-infinite-scroll on-infinite="addFriends()"></ion-infinite-scroll>
    </ion-list>

在controller中添加addFriends()函数,和载入数据。

同时,在重新完全载入数据后,需要发送一个scroll.infiniteScrollComplete事件,告诉directive,我们完成了这个动作,系统会清理scroller和为下一次的载入数据,重新绑定这一事件。

修改friends controller

通过修改controller,让list一次载入20个friends数据,这样达到Infinite Lists效果,如下修改js/controllers.js中FriendsCtrl:

.controller('FriendsCtrl', function($scope, Friends) {
    var currentStart = 0;
    $scope.friends = [];


  $scope.addFriends = function() {
    for (var i = currentStart; i < currentStart+20; i++) {
        $scope.friends.push(Friends.get(currentStart));
    }

    currentStart += 20;
    $scope.$broadcast('scroll.infiniteScrollComplete');
};

$scope.addFriends();
//$scope.friends = Friends.all();
})

service添加mock数据

在service端,调用Friends factory如下:
.factory('Friends', function() {
// Might use a resource here that returns a JSON array

// Some fake testing data
var friends = [
    { id: 0, name: 'Scruff McGruff' },
    { id: 1, name: 'G.I. Joe' },
    { id: 2, name: 'Miss Frizzle' },
    { id: 3, name: 'Ash Ketchum' },
    { id: 4, name: 'Scruff McGruff' },
    { id: 5, name: 'G.I. Joe' },
    { id: 6, name: 'Miss Frizzle' },
    { id: 7, name: 'Ash Ketchum' },
    { id: 8, name: 'Scruff McGruff' },
    { id: 9, name: 'G.I. Joe' },
    { id: 10, name: 'Miss Frizzle' },
    { id: 11, name: 'Ash Ketchum' },{ id: 0, name: 'Scruff McGruff' },
    { id: 12, name: 'G.I. Joe' },
    { id: 13, name: 'Miss Frizzle' },
    { id: 14, name: 'Ash Ketchum' },
    { id: 15, name: 'Scruff McGruff' },
    { id: 16, name: 'G.I. Joe' },
    { id: 17, name: 'Miss Frizzle' },
    { id: 18, name: 'Ash Ketchum' },
    { id: 19, name: 'Scruff McGruff' },
    { id: 20, name: 'G.I. Joe' },
    { id: 21, name: 'Miss Frizzle' },
    { id: 22, name: 'Ash Ketchum' },
    { id: 23, name: 'Scruff McGruff' },
    { id: 24, name: 'G.I. Joe' },
    { id: 25, name: 'Miss Frizzle' },
    { id: 26, name: 'Ash Ketchum' },
    { id: 27, name: 'Scruff McGruff' },
    { id: 28, name: 'G.I. Joe' },
    { id: 29, name: 'Miss Frizzle' },
    { id: 30, name: 'Ash Ketchum' },
    { id: 31, name: 'Scruff McGruff' },
    { id: 32, name: 'G.I. Joe' },
    { id: 33, name: 'Miss Frizzle' },
    { id: 34, name: 'Ash Ketchum' },
    { id: 35, name: 'Scruff McGruff' },
    { id: 36, name: 'G.I. Joe' },
    { id: 37, name: 'Miss Frizzle' },
    { id: 38, name: 'Ash Ketchum' },
    { id: 39, name: 'Scruff McGruff' }
  ];

return {
    all: function() {
      return friends;
    },
    get: function(friendId) {
      // Simple index lookup
    return friends[friendId];
    }
}

测试

使用python命令,测试:

python -m SimpleHTTPServer 8000

ion-infinite-scroll 参数

<ion-content ng-controller="MyController">
    <ion-infinite-scroll
        on-infinite="loadMore()"
        distance="1%">
    </ion-infinite-scroll>
</ion-content>

主要有三个参数:

  1. on-infinite:expression;含义:What to call when the scroller reaches the bottom.

  2. distance (optional) string; 含义:The distance from the bottom that the scroll must reach to trigger the on-infinite expression. Default: 1%.

  3. icon(optional) string;含义:The icon to show while loading. Default: 'ion-loading-d'.

也可以添加ng-if来判断是否还有更多数据可以载入,如:

<ion-infinite-scroll
    ng-if="moreDataCanBeLoaded()"
    icon="ion-loading-c"
    on-infinite="loadMoreData()">
</ion-infinite-scroll>

更多的ion-list使用,参照官网

转载于:https://www.cnblogs.com/yemeishu/p/3776602.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
本书是使用Zynq MPSoC的开发人员的实用指南,同样也是希望熟悉器件及其相关设计方法的技术人员的有效参考。 Zynq MPSoC(多处理器片上系统)是Xilinx公司推出的第二代SoC系列产品,集成了复杂的处理系统,包括ARM Cortex-A53应用程序处理器和ARM Cortex-R5实时处理器,以及FPGA可编程逻辑。 来自苏格兰斯特拉斯克莱德大学(University of Strathclyde)的Louise Crockett团队基于这一平台的软件和硬件结构,撰写了Exploring Zynq MPSoC: With PYNQ and Machine Learning Applications,综合且全面地介绍了软件堆栈、多处理器处理系统以及可编程硬件阵列等问题。 程序员可以学会如何使用简单的软件界面和框架来快速实现他们的机器学习算法,系统设计师可以利用它来获取系统的最高性能。 内容导读 器件的架构 与Zynq7000相比,Zynq MPSoC 进一步整合了处理器系统中可选择的处理器数量和性能,最多可配备四个ARM Cortex-A53处理器内核和两个ARM Cortex-R5实时处理器内核。此外,该架构进一步拓展了可编程逻辑门阵列中的DSP切片和分布式存储器的规模。在开发当今新兴的AI应用程序时,全新的MPSoC架构将实现繁琐的算术计算和数据移动的过程变得十分轻松有趣。 设计工具和方法 SoC系统将包括硬件设计和软件设计两个方面。硬件设计会映射到SoC设备上的FPGA逻辑资源,而软件则运行在一个或多个系统内部署的处理器上。在此设计流程中,硬件和软件开发可以在很大程度上独立进行,然后整合。工程师使用他们选择的工具生成硬件系统的元素,并使用Xilinx Vivado开发环境实现系统集成和实现目标设备。软件开发人员可以使用Xilinx软件开发工具包(SDK)进行开发。这是传统的软硬件协同设计方法。 Xilinx的SDx开发环境则是一种更高级的开发方式。在Xilinx SDx工具中可以完全使用软件代码对整个系统进行描述,然后对各种计算进行资源分配(在用户指导下)。这使得面向软件的软硬件协同设计已经发生了相当大的转变。本书的第4章中更详细地讨论了关于SDx设计方法。 更先进的应用实现 本书还讨论了Zynq上许多应用程序的实现,包括FINN-R开源框架的有效性神经网络的实现、基于PythonZynq设备框架和机器学习应用程序。我们可以预见到一些基于Zynq的更为优秀的产品,包括高级驾驶员辅助系统(ADAS),计算机视觉,“大数据”分析等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值