我有一个 SectionList,我用来自 firebase 的数据填充它。该列表显示事件信息按日期切片,用当月的可见光THIS MONTH,并使用自己的速记价值的其他日期JAN,FEB等等。
我得到的数据很好,可以很好地显示它,但我不知道如何按日期对数据数组进行分组。仅供参考,日期作为日期字符串 ' 2019-01-05'保存在数据库中,我使用 moment 使用此方法格式化它们:
formatDateToMonth(date) {
let fullDate = moment(date);
fullDate.month();
const month = fullDate.format('MMM');
return month.toUpperCase();
}
Run Code Online (Sandbox Code Playgroud)
返回JAN. 我运行一个简单的if语句来检查当前月份的 title 值,我用 moment 格式化,如果匹配,我将 title 的显示名称更改为THIS MONTH.
数据被推送到一个数组,如下所示:
listData.push({
data: [
{
id: event,
eventName: eventObj.eventName,
location: eventObj.location,
description: eventObj.description,
creatorsName: eventObj.creatorsName,
date: eventObj.date,
discipline: eventObj.discipline
}
],
title
});
Run Code Online (Sandbox Code Playgroud)
标题是月份名称和我需要对其进行排序和分组的键。
这是它目前的样子:
我希望同一月份的每个事件都在同一部分下。
任何帮助都会很棒!
完整组件:
import React from 'react';
import …Run Code Online (Sandbox Code Playgroud) 我的while循环不会在我设置它的条件下运行.
该计划的目的是使用存款金额,利率和目标金额确定存款金额到期的年数.
程序刚刚输入目标金额后停止,除非我将while语句从<=更改为> =在这种情况下它运行循环但返回在第100轮或1000等设置的年数...
#include <iostream>
#include <iomanip>
#include <string>
#include <math.h>
using namespace std;
int main()
{
//declare the variables
double rate,
balance = 0;
int deposit,
target,
years = 0;
cout << "****Lets make you some money!****" << endl << endl;
//input from the user
cout << "What is your deposit amount?: " << endl;
cin >> deposit;
cout << "What is your interest rate?: " << endl;
cin >> rate;
cout << "What is you target savings …Run Code Online (Sandbox Code Playgroud)