<small id='3vZgI'></small><noframes id='3vZgI'>

<i id='3vZgI'><tr id='3vZgI'><dt id='3vZgI'><q id='3vZgI'><span id='3vZgI'><b id='3vZgI'><form id='3vZgI'><ins id='3vZgI'></ins><ul id='3vZgI'></ul><sub id='3vZgI'></sub></form><legend id='3vZgI'></legend><bdo id='3vZgI'><pre id='3vZgI'><center id='3vZgI'></center></pre></bdo></b><th id='3vZgI'></th></span></q></dt></tr></i><div id='3vZgI'><tfoot id='3vZgI'></tfoot><dl id='3vZgI'><fieldset id='3vZgI'></fieldset></dl></div>
  • <tfoot id='3vZgI'></tfoot>

    <legend id='3vZgI'><style id='3vZgI'><dir id='3vZgI'><q id='3vZgI'></q></dir></style></legend>

        <bdo id='3vZgI'></bdo><ul id='3vZgI'></ul>

      1. Ionic v3:按日期/天分组列表

        Ionic v3: Group list by date/day(Ionic v3:按日期/天分组列表)

          <tbody id='xCMqd'></tbody>

        1. <tfoot id='xCMqd'></tfoot>
              <bdo id='xCMqd'></bdo><ul id='xCMqd'></ul>
              <i id='xCMqd'><tr id='xCMqd'><dt id='xCMqd'><q id='xCMqd'><span id='xCMqd'><b id='xCMqd'><form id='xCMqd'><ins id='xCMqd'></ins><ul id='xCMqd'></ul><sub id='xCMqd'></sub></form><legend id='xCMqd'></legend><bdo id='xCMqd'><pre id='xCMqd'><center id='xCMqd'></center></pre></bdo></b><th id='xCMqd'></th></span></q></dt></tr></i><div id='xCMqd'><tfoot id='xCMqd'></tfoot><dl id='xCMqd'><fieldset id='xCMqd'></fieldset></dl></div>
            • <legend id='xCMqd'><style id='xCMqd'><dir id='xCMqd'><q id='xCMqd'></q></dir></style></legend>

              <small id='xCMqd'></small><noframes id='xCMqd'>

                • 本文介绍了Ionic v3:按日期/天分组列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 Ionic 的旧版本 1 中,我能够构建一个按日期分组的事件列表,如下所示:

                  In good old version 1 of Ionic I was able to build an event-list grouped by date like this:

                  <ion-list ng-repeat="(key, value) in events| groupBy: 'event.date'">
                  
                    <div class="item item-divider" ng-if="value">
                      {{ ::key | event.date }}
                    </div>
                  
                    <ion-item class="item" ng-repeat="event in value track by event.event.event_id">
                      {{ ::event.event.title }}
                    </ionic-item>
                  
                  </ion-list> 
                  

                  虽然事件对象看起来像这样(事件 #1 和 #3 共享同一日期):

                  While the events object looks like this (event #1 and #3 share the same date):

                  {
                    "events": [
                      {
                        "id": 1,
                        "date": "2017-12-26",
                        "title": "First event"
                      },
                      {
                        "id": 2,
                        "date": "2017-12-30",
                        "title": "Second event"
                      },
                      {
                        "id": 3,
                        "date": "2017-12-26",
                        "title": "Third event"
                      },
                      {
                        "id": 4,
                        "date": "2017-12-31",
                        "title": "Last event"
                      }
                    ]
                  }
                  

                  这给了我一个存储在按event.date"分组的event"对象中的事件列表.因此,同一日期的所有事件都按项目分隔符分组:

                  This gave me a list of events stored in the "event" object grouped by "event.date". So all events on the same date where grouped by an item-divider:

                  +--------------+
                  + 2017-12-26   +
                  +--------------+
                  | First event  |
                  | Third event  |
                  +--------------+
                  + 2017-12-26   +
                  +--------------+
                  | Second event |
                  +--------------+
                  + 2017-12-26   |
                  +--------------+
                  | Last event   |
                  +--------------+
                  

                  如何使用 Ionic v3 实现这一点?有什么想法吗?

                  How to achieve this with Ionic v3? Any ideas?

                  推荐答案

                  您需要一个管道来将数据转换为可以在模板中轻松使用的结构:1 个对象数组,包含其他对象数组.您的最终数据应如下所示:

                  You need a pipe to transform your data into a structure you can easily use in a template: 1 array of objects, containing other arrays of objects. Your final data should look like this:

                  const events = [{
                    date: '2017-12-26',
                    events: [{
                      id: 1,
                      title: 'First event'
                    }, {
                      id: 3,
                      title: 'Third event'
                    }]
                  }, {
                    date: '2017-12-30',
                    events: [{
                      id: 2,
                      title: 'Second event'
                    }]
                  }, {
                    date: '2017-12-31',
                    events: [{
                      id: 4,
                      title: 'Last event'
                    }]
                  }];
                  

                  这是我在管道上的尝试:

                  Here is my attempt at a pipe that accomplishes that:

                  import { Pipe, PipeTransform } from '@angular/core';
                  
                  @Pipe({
                    name: 'groupBy',
                  })
                  export class GroupByPipe implements PipeTransform {
                    transform(value: any, groupByKey: string) {
                      const events: any[] = [];
                      const groupedElements: any = {};
                  
                      value.forEach((obj: any) => {
                        if (!(obj[groupByKey] in groupedElements)) {
                          groupedElements[obj[groupByKey]] = [];
                        }
                        groupedElements[obj[groupByKey]].push(obj);
                      });
                  
                      for (let prop in groupedElements) {
                        if (groupedElements.hasOwnProperty(prop)) {
                          events.push({
                            key: prop,
                            list: groupedElements[prop]
                          });
                        }
                      }
                  
                      return events;
                    }
                  }
                  

                  我确信有更好、更酷的方法来做到这一点(比如在一行中加上一些 ES6 的厉害之处),但目前这行得通.

                  I'm sure there are better, cooler ways to do this (like in one single line with some ES6 awesomeness) but this works for now.

                  现在对于模板,就像在 Ionic 1 中一样,基本上仍然有 2 个循环,第一个使用管道转换数据,第二个(内部)循环.

                  Now for the template, like you would in Ionic 1, you basically still have 2 loops, the first one uses the pipe to transform your data and the second (inner) loop.

                  这里有两个版本,第二个版本展示了如何使用管道对不同的键进行分组,并假设数据在原始 eventscategory 键> 数组:

                  Here are two versions, the second shows how the pipe can be used to group with different keys and assumes the data contains a category key in each element of the original events array:

                  <ion-item-group *ngFor="let group of events | groupBy: 'date'">
                      <ion-item-divider color="light">
                          {{ group.key }}
                      </ion-item-divider>
                      <ion-item *ngFor="let event of group.list">{{ event.title }}</ion-item>
                  </ion-item-group>
                  

                  按类别

                  <ion-item-group *ngFor="let group of events | groupBy: 'category'">
                      <ion-item-divider color="light">
                          {{ group.key }}
                      </ion-item-divider>
                      <ion-item *ngFor="let event of group.list">{{ event.title }} {{ event.date }}</ion-item>
                  </ion-item-group>
                  

                  您可以在模板中使用您希望使用的任何组件,这直接来自 Ionic 文档.

                  You can use whatever components you wish in your template, this is straight from the Ionic Documentation.

                  不要忘记在您使用它的页面中导入管道.如果使用了延迟加载,则需要将其添加到页面模块的 imports 中.

                  Don't forget to import the pipe in the page where you use it. If you used lazy loading, you need to add it to the imports of the page's module.

                  这篇关于Ionic v3:按日期/天分组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)
                  getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)
                    <bdo id='bYoH2'></bdo><ul id='bYoH2'></ul>
                        <tbody id='bYoH2'></tbody>

                      <tfoot id='bYoH2'></tfoot>
                    • <small id='bYoH2'></small><noframes id='bYoH2'>

                      <legend id='bYoH2'><style id='bYoH2'><dir id='bYoH2'><q id='bYoH2'></q></dir></style></legend>
                    • <i id='bYoH2'><tr id='bYoH2'><dt id='bYoH2'><q id='bYoH2'><span id='bYoH2'><b id='bYoH2'><form id='bYoH2'><ins id='bYoH2'></ins><ul id='bYoH2'></ul><sub id='bYoH2'></sub></form><legend id='bYoH2'></legend><bdo id='bYoH2'><pre id='bYoH2'><center id='bYoH2'></center></pre></bdo></b><th id='bYoH2'></th></span></q></dt></tr></i><div id='bYoH2'><tfoot id='bYoH2'></tfoot><dl id='bYoH2'><fieldset id='bYoH2'></fieldset></dl></div>