I am running into an issue with inserting a boolean value into the nested data within my Ionic/Angular Project.
My goal is to include a boolean value for each day's time (if it exists) in a JSON structure that cannot be altered due to strict HTTP call constraints. The current JSON format is as follows:
{
"all_year": true,
"season_from": "01/01",
"season_to": "12/31",
"monday": [
"08:30am"
],
"tuesday": [
"08:30am"
],
"wednesday": [
"08:00am", "09:30am", "01:30pm"
],
"thursday": [
"08:30am", "09:30am"
],
"friday": [
"08:30am"
],
"saturday": [],
"sunday": []
}
The resulting output appears like this https://i.sstatic.net/INfh8.png
Here is the HTML code snippet:
<ion-list ng-repeat="(key, value) in filteredDays"
ng-model="value.checked"
ng-checked ="value.checked">
<div class="item item-divider">
<h3>{{key}}</h3><!--{{value}}--></div>
<ion-toggle ng-repeat="x in value"
ng-model="value"
ng-checked="x"
>
{{x}}
</ion-toggle>
This is how I have set up my JavaScript:
$scope.filteredDays={};
$scope.unFilteredDays = {
"all_year": true,
"season_from": "01/01",
"season_to": "12/31",
"monday": [
"08:30am"
],
"tuesday": [
"08:30am"
],
"wednesday": [
"08:00am", "09:30am", "01:30pm"
],
"thursday": [
"08:30am", "09:30am"
],
"friday": [
"08:30am"
],
"saturday": [],
"sunday": []
};
$scope.filteredDays = $scope.unFilteredDays;
// Struggling at this point
/*
var checked = false;
$scope.filteredDays.forEach($scope.filteredDays, function(value, key) {
$scope.filteredDays.push(checked);
});
*/
I have indicated where I am facing difficulties in the above code block. I am unable to figure out a way to add a boolean value to the time toggle item array. I have also created a CodePen demo for reference.
Moreover, I have attempted to utilize lodash in this project to manage the data (extracting "all_year", "season_from", "season_to" values from the list) and believe that it is configured correctly. However, my limited experience with lodash is hindering me from achieving the desired outcome.
Any assistance or guidance would be greatly appreciated.