返回介绍

Ionic4 排序组件 ion-reorder-group

发布于 2019-11-22 18:04:18 字数 7537 浏览 991 评论 0 收藏 0

Ionic4项目中我们可以使用Ionic4排序组件ion-reorder-group对项目进行布局。

ion-reorder-group官方文档地址:https://ionicframework.com/docs/api/reorder-group

The reorder group is a wrapper component for items using the ion-reorder component. See the Reorder documentation for further information about the anchor component that is used to drag items within the ion-reorder-group.

Once the user drags an item and drops it in a new position, the ionItemReorder event is dispatched. A handler for it should be implemented that calls the complete() method.

The detail property of the ionItemReorder event includes all of the relevant information about the reorder operation, including the from and to indexes. In the context of reordering, an item moves from an index to a new index.

ion-reorder-group 用法(Usage)



  
  
    
      Item 1
    
    
  

  
    
      Item 2
    
    
  

  
  
    
    
      Item 3
    
  

  
    
    
      Item 4
    
  

  
  
    
      Item 5
    
    
      
    
  

  
    
      Item 6
    
    
      
    
  

  
  
    
      
        Item 7
      
    
  

  
    
      
        Item 8
      
    
  
</ion-reorder-group>
import { Component, ViewChild } from '@angular/core';
import { IonReorderGroup } from '@ionic/angular';

@Component({
  selector: 'reorder-group-example',
  templateUrl: 'reorder-group-example.html',
  styleUrls: ['./reorder-group-example.css']
})
export class ReorderGroupExample {
  @ViewChild(IonReorderGroup) reorderGroup: IonReorderGroup;

  constructor() {}

  doReorder(ev: any) => {
    // The `from` and `to` properties contain the index of the item
    // when the drag started and ended, respectively
    console.log('Dragged from index', ev.detail.from, 'to', ev.detail.to);

    // Finish the reorder and position the item in the DOM based on
    // where the gesture ended. This method can also be called directly
    // by the reorder group
    ev.detail.complete();
  });

  toggleReorderGroup() {
    this.reorderGroup.disabled = !this.reorderGroup.disabled;
  }
}

Updating Data

import { Component, ViewChild } from '@angular/core';
import { IonReorderGroup } from '@ionic/angular';

@Component({
  selector: 'reorder-group-example',
  templateUrl: 'reorder-group-example.html',
  styleUrls: ['./reorder-group-example.css']
})
export class ReorderGroupExample {
  items = [1, 2, 3, 4, 5];

  @ViewChild(IonReorderGroup) reorderGroup: IonReorderGroup;

  constructor() {}

  doReorder(ev: any) => {
    // Before complete is called with the items they will remain in the
    // order before the drag
    console.log('Before complete', this.items);

    // Finish the reorder and position the item in the DOM based on
    // where the gesture ended. Update the items variable to the
    // new order of items
    this.items = ev.detail.complete(this.items);

    // After complete is called the items will be in the new order
    console.log('After complete', this.items);
  });
}


  
  
    
      Item 1
    
    
  

  
    
      Item 2
    
    
  

  
  
    
    
      Item 3
    
  

  
    
    
      Item 4
    
  

  
  
    
      Item 5
    
    
      
    
  

  
    
      Item 6
    
    
      
    
  

  
  
    
      
        Item 7
      
    
  

  
    
      
        Item 8
      
    
  
</ion-reorder-group>
const reorderGroup = document.querySelector('ion-reorder-group');

reorderGroup.addEventListener('ionItemReorder', ({detail}) => {
  // The `from` and `to` properties contain the index of the item
  // when the drag started and ended, respectively
  console.log('Dragged from index', detail.from, 'to', detail.to);

  // Finish the reorder and position the item in the DOM based on
  // where the gesture ended. This method can also be called directly
  // by the reorder group
  detail.complete();
});

Updating Data

const items = [1, 2, 3, 4, 5];
const reorderGroup = document.querySelector('ion-reorder-group');

reorderGroup.addEventListener('ionItemReorder', ({detail}) => {
  // Before complete is called with the items they will remain in the
  // order before the drag
  console.log('Before complete', items);

  // Finish the reorder and position the item in the DOM based on
  // where the gesture ended. Update the items variable to the
  // new order of items
  items = detail.complete(items);

  // After complete is called the items will be in the new order
  console.log('After complete', items);
});
import React from 'react';

import { IonItem, IonLabel, IonReorder, IonReorderGroup, IonIcon } from '@ionic/react';

function doReorder(event: CustomEvent) {
  // The `from` and `to` properties contain the index of the item
  // when the drag started and ended, respectively
  console.log('Dragged from index', event.detail.from, 'to', event.detail.to);

  // Finish the reorder and position the item in the DOM based on
  // where the gesture ended. This method can also be called directly
  // by the reorder group
  event.detail.complete();
}

const Example: React.SFC = () => (
  
    {/*-- The reorder gesture is disabled by default, enable it to drag and drop items --*/}
    
      {/*-- Default reorder icon, end aligned items --*/}
      
        
          Item 1
        
        
      

      
        
          Item 2
        
        
      

      {/*-- Default reorder icon, start aligned items --*/}
      
        
        
          Item 3
        
      

      
        
        
          Item 4
        
      

      {/*-- Custom reorder icon end items --*/}
      
        
          Item 5
        
        
          
        
      

      
        
          Item 6
        
        
          
        
      

      {/*-- Items wrapped in a reorder, entire item can be dragged --*/}
      
        
          
            Item 7
          
        
      

      
        
          
            Item 8
          
        
      
    
  
  }
);

export default Example

Updating Data

const items = [1, 2, 3, 4, 5];

function doReorder(event: CustomEvent) {
  // Before complete is called with the items they will remain in the
  // order before the drag
  console.log('Before complete', this.items);

  // Finish the reorder and position the item in the DOM based on
  // where the gesture ended. Update the items variable to the
  // new order of items
  this.items = event.detail.complete(this.items);

  // After complete is called the items will be in the new order
  console.log('After complete', this.items);
}

  
  
    
    
      
        Item 1
      
      
    

    
      
        Item 2
      
      
    

    
    
      
      
        Item 3
      
    

    
      
      
        Item 4
      
    

    
    
      
        Item 5
      
      
        <ion-icon name<span class="token pu
                  
                  
                

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文