Ionic Foundation - Listion-list

Keywords: Attribute angular iOS Javascript

List: ion-list

Listing is a common way of organizing information. In ionic, list elements are declared using ion-list instructions, and member elements are declared using ion-item instructions:

  1. <ion-list>   
  2.    <ion-item>...</ion-item>   
  3.    <ion-item>...</ion-item>   
  4.    ...   
  5. </ion-list>  
The ion-list Directive provides the following attributes to customize the look of the list:

  • Type - List type. The type attribute is optional and can be used to set the type of list: list-inset | card. Both lists have built-in effects, but the difference is that the card list has a border shadow effect.
  • Show-delete - Whether to display the delete button within a member. The show-delete attribute is optional. If there is an ion-delete-button in a member, use this attribute to notify the list whether the element delete button is displayed. The allowable value is: true | false.
  • Show-reorder - Displays the reorder button within a member. The show-reorder attribute is optional. If there is an ion-reorder-button within a member, use this attribute to notify the list whether the element reorder button is displayed. The allowable value is: true | false.
  • can-swipe - Whether sliding mode is supported to display member option buttons. The can-switch attribute is optional. If there is an option button in a member, use this property to allow or prohibit opening the option button by sliding the member to the left. The allowable value is: true | false, which defaults to true.
  1. <!DOCTYPE html>  
  2. <html ng-app="myApp">  
  3. <head>  
  4.     <meta charset="UTF-8">  
  5.     <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no,width=device-width,height=device-height">  
  6.     <script src="../lib/js/ionic.bundle.min.js"></script>  
  7.     <link rel="stylesheet" type="text/css" href="../lib/css/ionic.min.css">  
  8.   
  9. </head>  
  10. <body  ng-controller="myCtrl">  
  11.     <ion-header-bar class="bar-positive">  
  12.         <h1 class="title">ion-list</h1>  
  13.     </ion-header-bar>  
  14.     <ion-content>  
  15.         <ion-list can-swipe="true">  
  16.             <ion-item ng-repeat="item in items">  
  17.             {{item}}  
  18.                 <ion-option-button class="button-calm icon ion-edit"></ion-option-button>  
  19.                 <ion-option-button class="button-energized icon ion-share"></ion-option-button>  
  20.             </ion-item>  
  21.         </ion-list>  
  22.     </ion-content>  
  23. </body>  
  24. </html>  
  25.   
  26. <script>  
  27. angular.module("myApp",["ionic"])  
  28. .controller("myCtrl",function($scope){  
  29.     $scope.items = [];  
  30.     for(var i=0;i<10;i++)   
  31.         $scope.items.push(["item list ",i+1].join(""));  
  32. });  
  33.   
  34. </script>  

II. ion-list ion-item members
ion-item has three predefined buttons:
  • ion-option-button-option button. An ion-item can contain multiple option buttons. The option button is hidden and requires the user to slide members to the left to display the option button. You can use the can-swipe attribute of ion-list to allow or prohibit sliding open option buttons. Using the ng-click instruction to hook the click event listener function, the prototype is as follows:
    1. var optionListener = function(item){...}   
    When ionic captures a user's click event, it calls this function and passes it into the current item object.  
  • ion-delete-button-Delete button There is at most one Delete button in an ion-item. The Delete button is always on the left-most end of the member when it is displayed. The show-delete attribute of ion-list can be used to display or hide the delete button and the ng-click instruction can be used to hook the click event listener function. The prototype is as follows:
    1. var deleteListener = function(item){...}  
    When ionic captures a user's click event, it calls this function and passes it into the current item object.  
  • ion-reorder-button-rearrangement button There is at most one rearrangement button in an ion-item. The rearrangement button is always at the right end of the member when it is displayed. You can use the show-reorder attribute of ion-list to display or hide the rearrangement button and use the on-reorder attribute to hook the rearrangement event listener function. Its prototype is as follows:
    1. var reorderListener = function(item,$fromIndex,$toIndex){...}   
    When ionic captures a user's rearrangement event, it calls this function and passes in the current item object, the original serial number and the target serial number.
  1. <!DOCTYPE html>  
  2. <html ng-app="myApp">  
  3. <head>  
  4.     <meta charset="UTF-8">  
  5.     <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no,width=device-width,height=device-height">  
  6.     <script src="../lib/js/ionic.bundle.min.js"></script>  
  7.     <link rel="stylesheet" type="text/css" href="../lib/css/ionic.min.css">  
  8. </head>  
  9. <body ng-controller="myCtrl">  
  10.     <ion-header-bar class="bar-positive">  
  11.         <a class="button button-clear icon ion-ios-minus-outline" ng-click="flag.showDelete=!flag.showDelete;flag.showReorder=false;"></a>  
  12.         <h1 class="title">Member button</h1>  
  13.         <a class="button" ng-click="flag.showReorder=!flag.showReorder;flag.showDelete=false;">Rescheduling</a>  
  14.     </ion-header-bar>  
  15.     <ion-content>  
  16.         <ion-list show-delete="flag.showDelete" show-reorder="flag.showReorder">  
  17.             <ion-item ng-repeat="item in items">  
  18.                 {{item}}!  
  19.                 <ion-option-button class="button-calm">...</ion-option-button>  
  20.   
  21.                 <ion-delete-button class="ion-minus-circled" ng-click="delete_item(item)"></ion-delete-button>  
  22.                 <ion-reorder-button class="ion-navicon" on-reorder="move_item(item,$fromIndex,$toIndex)"></ion-reorder-button>  
  23.             </ion-item>  
  24.         </ion-list>  
  25.     </ion-content>  
  26. </body>  
  27. </html>  
  28.   
  29. <script>  
  30. angular.module("myApp",["ionic"])  
  31. .controller("myCtrl",function($scope){  
  32.     $scope.flag={showDelete:false,showReorder:false};  
  33.     $scope.items=["Chinese","English","German","Italian","Janapese","Sweden","Koeran","Russian","French"];  
  34.     $scope.delete_item=function(item){  
  35.         var idx = $scope.items.indexOf(item);  
  36.         $scope.items.splice(idx,1);  
  37.     };  
  38.     $scope.move_item = function(item, fromIndex, toIndex) {  
  39.   
  40.         console.log(fromIndex);  
  41.         console.log(toIndex);  
  42.   
  43.         console.log(item);  
  44.   
  45.         $scope.items.splice(fromIndex, 1);  
  46.         $scope.items.splice(toIndex, 0, item);  
  47.         console.log(item);  
  48.     };  
  49. });  
      
collection-repeat: High Performance ng-repeat
collection-repeat instructions are similar to ng-repeat instructions, but they are more suitable for large amount of list data because they only render data in the visual area to DOM:
  1. <any collection-repeat="...">...</any>  
The collection-repeat instruction accepts an enumeration expression and can attach the following attributes:
  • item-width-optional. Declare the width of duplicate elements
  • item-height-optional. Declare the height of duplicate elements
  • item-render-buffer-optional. The number of visual data before and after loading the rendering buffer. The default is 3.
  • force-refresh-images-optional. Whether the image is forced to refresh when scrolling. Permissible value: true | false
  1. <!DOCTYPE html>  
  2. <html ng-app="myApp">  
  3. <head>  
  4.     <meta charset="UTF-8">  
  5.     <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no,width=device-width,height=device-height">  
  6.     <script src="../lib/js/ionic.bundle.min.js"></script>  
  7.     <link rel="stylesheet" type="text/css" href="../lib/css/ionic.min.css">  
  8. </head>  
  9. <body  ng-controller="myCtrl">  
  10.     <ion-header-bar class="bar-positive">  
  11.         <h1 class="title">collection-repeat</h1>  
  12.     </ion-header-bar>  
  13.     <ion-content>  
  14.         <ion-list>  
  15.             <ion-item collection-repeat="item in items">  
  16.             {{item}}  
  17.             <ion-option-button class="button-positive">...</ion-option-button>  
  18.             </ion-item>  
  19.         </ion-list>  
  20.     </ion-content>  
  21.     <script type="text/javascript">  
  22. angular.module("myApp",["ionic"])  
  23. .controller("myCtrl",function($scope){  
  24.     $scope.items = [];  
  25.     for(var i=0;i<5000;i++)  
  26.         $scope.items.push(["item",i+1].join(""));  
  27. });  
  28. </script>  
  29. </body>  
  30. </html>  


IV. Script Interface: $ionicListDelegate
If you need to control list elements from scripts, you can use the $ionicListDelegate service:
  • showReorder([showReorder]) - Display/close the sort button showReorder is allowed to be true | false. You can use an expression in scope.
  • showDelete([showDelete]) - Display/close the delete button showDelete with the allowable value of true | false. You can use an expression in scope.
  • Can Swipe Items ([can Swipe Items]) - Whether the allowable value of the member option button can Swipe Items is allowed to be displayed by sliding: true | false. You can use a scoped expression closeOptionButtons() - close all options buttons.
  1. <!DOCTYPE html>  
  2. <html ng-app="ezApp">  
  3. <head>  
  4.     <meta charset="UTF-8">  
  5.     <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no,width=device-width,height=device-height">  
  6.     <script src="../lib/js/ionic.bundle.min.js"></script>  
  7.     <link rel="stylesheet" type="text/css" href="../lib/css/ionic.min.css">  
  8. </head>  
  9. <body  ng-controller="myCtrl">  
  10.     <ion-header-bar align-title="left" class="bar-positive">  
  11.         <h1 class="title">$ionicListDelegate</h1>  
  12.         <a class="button" ng-click="close();">choosing close</a>  
  13.     </ion-header-bar>  
  14.     <ion-content>  
  15.         <ion-list>  
  16.             <ion-item ng-repeat="item in items">  
  17.                 {{item}}!  
  18.                 <ion-option-button class="button-calm icon ion-share"></ion-option-button>  
  19.             </ion-item>  
  20.         </ion-list>  
  21.     </ion-content>  
  22. </body>  
  23. </html>  
  24.   
  25.   
  26. <script>  
  27. angular.module("ezApp",["ionic"])  
  28. .controller("myCtrl",["$scope","$ionicListDelegate",function($scope,$ionicListDelegate){  
  29.     $scope.items = ["Chinese","English","Russian","Japanese"];  
  30.     var flag = false;  
  31.     $scope.close = function(){  
  32.         $ionicListDelegate.closeOptionButtons();  
  33.     };  
  34. }]);  
  35.   
  36. </script>  

Posted by phpeanuts on Fri, 31 May 2019 17:56:23 -0700