SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2013
    Location
    Greece
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    array becoming complicated

    I am trying to make an events calendar based on this tutorial.
    The calendar depicts events by accepting JSON(an array of objects where each object contains data related event) by the server.
    Here is an example:

    Code:
    {id:3, title:kostas, staff_ID:5, start:2014-04-09 04:30:00, end:2014-04-09 06:00:00, color:#0072C6,}
    The above is what I see in the network tab of dev tools.

    Here is the result of the above:http://1drv.ms/1if2oZ5

    I have a problem though:
    All the above data are taken from a single table row...there is some data though that exist in another table and it MAY be comprised of more that one row
    It is a table which list services chosen by user and as you might guess an event might be associated with more than service(meaning more than one row).

    How could I incorporate the services in the above JSON?
    Should I add another member where it will be an array containing the services?

  2. #2
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,398
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    How does the data about the services relate to the calendar events?
    "There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies."

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2013
    Location
    Greece
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by fretburner View Post
    How does the data about the services relate to the calendar events?
    yes,I must clarify that.The events calendar is actually a calendar where appointments are stored...and an appointment(in a hair salon for example) might be associated with more than one service-as is often the case.

    Does it make sense now?

  4. #4
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,398
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    You could nest them within the appointment object:

    Code JavaScript:
    {
        id:3,
        title: 'kostas', 
        staff_ID:5,
        start:2014-04-09 04:30:00,
        end:2014-04-09 06:00:00,
        services: [
            {
                id:6,
                name: 'cut'
            },
            {
                id:8,
                name: 'perm'
            }
        ]
    }

    If you don't need to display them unless the user clicks the appointment for more information (for example), then you could return the information about the services in a separate request, from a separate end-point of your API, to keep things cleaner.
    "There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies."

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2013
    Location
    Greece
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by fretburner View Post
    You could nest them within the appointment object:

    Code JavaScript:
    {
        id:3,
        title: 'kostas', 
        staff_ID:5,
        start:2014-04-09 04:30:00,
        end:2014-04-09 06:00:00,
        services: [
            {
                id:6,
                name: 'cut'
            },
            {
                id:8,
                name: 'perm'
            }
        ]
    }

    If you don't need to display them unless the user clicks the appointment for more information (for example), then you could return the information about the services in a separate request, from a separate end-point of your API, to keep things cleaner.
    You guessed right I want to display the services on clicking the appointment which might lead me adopt your advise-making a separate request for that.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •