EDIT: If ID number is not sequential, it won't return the values for the detail page


#1

Using the demo to build upon, I can not get a detail page with the values. I can place the same variables on the index page and they work.

Having played with it some more, I realized that if a box has an id of 9, but there are only 4 in total, it breaks and will not return the values for it. I will have an app that will have non-sequential id’s. Is there a way around this? Will it matter as the index of the json will be what it runs off? Somewhat confused.

So 0-5 works, but 0, 181, 10, 2, 1 does not.


#2

The id inside your object isn’t the same as the index of the array. So when you look for miboxes[180] nothing is found. miboxes[0] would return the result as there is one item (index 0) in the array. I’m probably the wrong person to give advice, since I’m new to Javascript, but in your get method, you could iterate over each item in the array until you found one that matched. There’s probably a better way.

//untested    
get: function(miboxId) {
      for (var i = 0; i < miboxes.length; i++)
        {
          if (miboxes[i].id === miboxId) { return miboxes[i]; }
        }
    }

#3

Interesting approach! I’ll give it a try!


#4

It worked. I had to make a small tweak to the code

(miboxes[i].id === miboxId) to (miboxes[i].id == miboxId)

Thanks for your help!