I am trying to create something similar to this:
"ABCDEF", "GHIJK", "LMNO", "PRSTU", "VYZXWQ", "0123456789"
I have a list in alphabetical order; I want names starting with "ABCDEF" to be in one array and names starting with "GHIJK" in another.
But I'm unsure of how to accomplish this.
The data I have looks like this:
[
{
"publishDate": "02.08.2022",
"jobs": [
{
"mediaName": "GERCEKTARAF.COM",
"ids": [
{
"id": "62ebea1fasfascbd755d317d1ffc9c",
"isLocked": false
}
]
},
{
"mediaName": "MEDYAGAZETE.COM",
"ids": [
{
"id": "62ec1asdddc0e45625ab485f38a5",
"isLocked": false
}
]
},
{
"mediaName": "FINANS.GAZETEVATAN.COM",
"ids": [
{
"id": "62ecasdasd1dbfe45625ab485f382c",
"isLocked": false
},
{
"id": "62ec1dasdasdfc0e45625ab485f3897",
"isLocked": false
}
]
}
]
}
]
(I need the mediaNames under the jobs array to be sorted according to my criteria, regardless of publish date)
Here is my code;
Typescript side:
getJobsForInternet() {
this.sidenavService.getInternetJobs().subscribe((jobs: any) => {
jobs.forEach(getInternetJobs => {
getInternetJobs.jobs.sort((a, b) => {
let _a = a.mediaName
let _b = b.mediaName
return _a.toString().localeCompare(_b, 'tr', { sensitivity: 'base' });
})
});
this.getJobs = jobs
console.log(this.getJobs)
});
}
HTML side:
<nav class="dbt-tree-nav">
<details *ngFor="let internetJobs of getJobs " class="dbt-tree-nav__item is-expandable">
<summary class="dbt-tree-nav__item-title">{{ internetJobs.publishDate }}</summary>
<details class="dbt-tree-nav__item is-expandable">
------ I wrote this part by hand for now, but it should be dynamic ------
<summary class="dbt-tree-nav__item-title">Internet_ABCDEF</summary>
------ I wrote this part by hand for now, but it should be dynamic ------
<details class="last-internet dbt-tree-nav__item is-expandable">
<summary class="last-internet dbt-tree-nav__item-title">
(1) {{internetJobs.jobs.length }}
</summary>
</details>
</details>
</details>
</nav>