Task: To retrieve and display data based on the current event ID from a JSON file:
var _getEventById = function(eventId) {
var __findEvent = function(event) {
return event.id === eventId;
};
return _.find(data.meeting.events, __findEvent);
};
I am attempting to find the previous and next event numbers using the current event ID. The following code, which is placed inside the model, is not functioning as intended.
var _getNextEvent = function(eventNumber) {
var nextEventNumber = data.meeting.events.number += eventNumber ;
var nextEvent = _.find(event, function(event) {
return event.number === nextEventNumber;
});
return nextEvent.id;
};
var _getPrevEvent = function(eventNumber) {
var prevEventNumber = data.meeting.events.number -= eventNumber ;
var prevEvent = _.find(event, function(event) {
return event.number === prevEventNumber;
});
return prevEvent.id;
};
My approach involves passing the current event's ID to find the event number using Lodash and incrementing it by one to find the next event's number, then returning its ID. (Similarly, decrementing to find the previous event's ID)
JSON: "meeting": {
"id": "SING_74",
"name": "Singapore Racing",
"runDate": "2017-10-04",
"meetingNumber": 12,
"closeDate": "2017-10-04",
"open": true,
"venue": "Overseas",
"currentRaceId": "SING_74_2",
"code": "RACE",
**"events": [**
{
**"id": "SING_74_1",**
**"number": 1,**
"open": false,
"status": "Closed"
},
{
"id": "SING_74_3",
"number": 3,
"open": true,
"status": "Open"
},
{
"id": "SING_74_4",
"number": 4,
"open": true,
"status": "Open"
},
{
"id": "SING_74_5",
"number": 5,
"open": true,
"status": "Open"
},
Goal: My objective in Angular is to enable users to swipe on the Racing/events and detect ng-swipe-left and ng-swipe-right gestures to update the data with the next event ID or previous event ID.
If you have any insights or examples to share, they would be greatly appreciated.