<ion-select-option> looping one ngfor loop inside another - arrays

I'm fairly new to Ionic so please bear with me.
I've managed to create a very simple array called Events that has another small array inside it:
$key: "12345566778"
dates: Array(3)
0: Tue Feb 23 2021 00:00:00 GMT+0000 (Greenwich Mean Time) {}
1: Wed Feb 24 2021 00:00:00 GMT+0000 (Greenwich Mean Time) {}
2: Thu Feb 25 2021 00:00:00 GMT+0000 (Greenwich Mean Time) {}
title: "Quality"
startDate: "2021-02-23"
$key: "314351632623"
dates: Array(3)
0: Wed Feb 17 2021 00:00:00 GMT+0000 (Greenwich Mean Time) {}
1: Thu Feb 18 2021 00:00:00 GMT+0000 (Greenwich Mean Time) {}
2: Fri Feb 19 2021 00:00:00 GMT+0000 (Greenwich Mean Time) {}
title: "Equality"
startDate: "2021-02-17"
What I really want to do is display them in an list in the following format:
Quality
- Tue Feb 23 2021
- Wed Feb 24 2021
- Thu Feb 25 2021
Equality
- Wed Feb 17 2021
- Thu Feb 18 2021
- Fri Feb 19 2021
But at the moment I only know how to cycle through the events array with one ngFor, which isn't what I'm wanting to do:
<ion-select-option *ngFor="let event of Events" value="{{event.title}} - {{event.startDate}}">{{event.title}} - {{event.startDate}}</ion-select-option>
Does anyone know how I can achieve this please?

You just need to nest another loop to achieve that. It'd look like this:
<ion-item *ngFor="let event of Events">
<ion-label>{{ event.title }}</ion-label>
<ion-select>
<ion-select-option *ngFor="let eventDate of event.dates" [value]="eventDate">
{{ eventDate | date:'EEE LLL dd yyyy' }}
</ion-select-option>
</ion-select>
</ion-item>
You'd probably need to edit that code based on your specific UI, but the main idea is to have one loop for the events, and another loop for the dates on each event.
Please also notice that I'm using the Angular date pipe to format the eventDate (https://angular.io/api/common/DatePipe)
EDIT:
I'm trying to get all the results sitting within one ion-select, each as an option. Then I was going to make the titles unselectable and the whole thing multiple choice but that's not really important here.
For some reason I assumed you wanted multiple ion-selects but that makes perfect sense.
In that case, you can use <ng-container></ng-container> to create a nested loop without creating an element that will be rendered in the view.
I think something like this should work (I'm editing the code directly in the browser so you may need to fix a few things, but the main idea at least should be clear).
<ion-item>
<ion-label>Options</ion-label>
<ion-select>
<ng-container *ngFor="let event of Events">
<!-- Title -->
<ion-select-option disabled="true">
{{ event.title }}
</ion-select-option>
<!-- Options -->
<ion-select-option *ngFor="let eventDate of event.dates" [value]="eventDate">
{{ eventDate | date:'EEE LLL dd yyyy' }}
</ion-select-option>
</ng-container>
</ion-select>
</ion-item>

Related

Date object convert to moment object

I am using ReactJs to create DateTime picker. Now my problem is how the date object converts to the moment object.
For example below is the date object, this object just show the value of date object:
Wed Sep 21 2022 00:17 GMT+0800 (Malaysia Time)
How can I convert to the moment object like below sample:
Moment {_isAMomentObject: true, _i: Wed Sep 21 2022 00:27:50 GMT+0800 (Malaysia Time), _isUTC: false, _pf: {…}, _locale: Locale, …}
_d
:
Wed Sep 21 2022 00:17:50 GMT+0800 (Malaysia Time) {}
_i
:
Wed Sep 21 2022 00:27:50 GMT+0800 (Malaysia Time) {}
_isAMomentObject
:
true
_isUTC
:
false
_isValid
:
true
_locale
:
Locale {_calendar: {…}, _longDateFormat: {…}, _invalidDate: 'Invalid date', _dayOfMonthOrdinalParse: /\d{1,2}(th|st|nd|rd)/, ordinal: ƒ, …}
_pf
:
{empty: false, unusedTokens: Array(0), unusedInput: Array(0), overflow: -2, charsLeftOver: 0, …}
[[Prototype]]
:
Object
I don't want to show the date object like the below picture:
Hope someone can guide me on how to solve this problem. Is possible to solve this? Thanks.
Perhaps you should use the following library: moment.
Here is the link to their website, the documentation is pretty well done.
Link to the site: https://momentjs.com/
I hope it will help you, i use this librairy all the time :)

how to get react-dropzone metadata specifically dat file was created

Anyone know how to find metadata from react-dropzone. Currently out of the box it just shows the following:
path: "DSCF2953.jpg"
lastModified: 1643308695461
lastModifiedDate: Thu Jan 27 2022 10:38:15 GMT-0800 (Pacific Standard Time) {}
name: "DSCF2953.jpg"
size: 1442377
type: "image/jpeg"
It shows nothing about the date created type of camera and on....
Is there a way to get to extra file data ?

My date function is not working on firefox but works on chrome

I am using Date() function in my react code. Date function is running on chrome fine but working on firefox.
I have tried to convert the date in miliseconds.
var getnewdate = "Wed Jun 26 2019 00:00:00 GMT+0530 (India Standard Time)";
alert(getnewdate);
var getCurrentDayInMilli = new Date(getnewdate).getTime() / 100000;
alert(getCurrentDayInMilli);
alert(getnewdate); prints "Tue Jun 25 2019 00:00:00 GMT+0530 (India Standard Time)" on chrome which is correct but on firefox it prints "Invalid Date" which is not correct.
I want my alert function should work fine in firefox as well like chrome.
Use date in this format yyyy/MM/dd(you can have any format of date) HH:mm:ss(this is required), this will work in all the browsers,
var getselectdate = "Jun-27-2019 12:00:00";

How to convert "Mon Mar 14 2014 00:00:00 GMT+0530 (IST)" into 2014-03-08 using Moment.js

In AngularJS i.e in controller.js file I am retrieving the date from database in this format i.e "Mon Mar 14 2014 00:00:00 GMT+0530 (IST)". But when I display this date using AngularJS datepicker on html page it is showing empty means it is not showing the date with this format i.e 2014-03-08.
Here's example on how to convert date format using moment js
<div id="date"></div>
<div id="momentdate"></div>
<script>
$(document).ready(function () {
var d = new Date(); //Sat Mar 05 2016 17:48:48 GMT+0530 (India Standard Time)
$('#date').text(d);
var md = moment(d).format('YYYY-MM-DD');
$('#momentdate').text(md);
});
</script>
output
Sat Mar 05 2016 17:48:48 GMT+0530 (India Standard Time)
2016-03-05
working example on jsfiddle

GAE JSP not compiling with jar in WEB-INF

This may be a simple issue but i am spinning my wheels at this point. I am using the google app engine, and I have a simple jsp that has the following snippit in it
<%#page import="main.java.psbdom.*" %>
....
<%= PS_STRINGS.LABEL %>
and then i have a jar in the WEB-INF/lib dir that has this contents
$ jar -tvf psbdom-0.0.1-SNAPSHOT.jar
0 Tue Feb 07 19:11:36 EST 2012 META-INF/
124 Tue Feb 07 19:11:34 EST 2012 META-INF/MANIFEST.MF
0 Fri Feb 03 20:42:30 EST 2012 main/
0 Fri Feb 03 20:42:30 EST 2012 main/java/
0 Fri Feb 03 20:42:30 EST 2012 main/java/psbdom/
0 Fri Feb 03 20:42:30 EST 2012 main/java/psbdom/constants/
0 Fri Feb 03 20:42:30 EST 2012 main/java/psbdom/data/
0 Fri Feb 03 20:42:30 EST 2012 main/java/psbdom/user/
602 Tue Feb 07 19:11:32 EST 2012 main/java/psbdom/constants/PS_STRINGS.class
this is the PS_STRINGS class
public class PS_STRINGS
{
//public static final String
public static final String LABEL = "LABEL";
...
}
and i get this error
An error occurred at line: 9 in the jsp file: /admin/addConcept.jsp
PS_STRINGS.LABEL cannot be resolved to a type
6: <title>Add Concept</title>
7: </head>
8: <body>
9: <%= PS_STRINGS.LABEL %>
i am really baffled as to what i am doing wrong and any help would be greatly appreciated.
thanks
J
You got the "import.*" wrong, The wildcard (import *) only applies to classes, not to sub-packages.
Try
<%#page import="main.java.psbdom.*, main.java.psbdom.constants.*" %>

Resources