Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
795
binding to associative array
posted

In your examples you have:

            var products = [];

            products[0] = { "ProductID": 1, "Name": "Adjustable Race", "ProductNumber": "AR-5381" };

            products[1] = { "ProductID": 2, "Name": "Bearing Ball", "ProductNumber": "BA-8327" };

            products[2] = { "ProductID": 3, "Name": "BB Ball Bearing", "ProductNumber": "BE-2349" };

            products[3] = { "ProductID": 4, "Name": "Headset Ball Bearings", "ProductNumber": "BE-2908" };

this works fine, but what if I wanted it instead to be:

            products[1] = { "ProductID": 1, "Name": "Adjustable Race", "ProductNumber": "AR-5381" };

            products[2] = { "ProductID": 2, "Name": "Bearing Ball", "ProductNumber": "BA-8327" };

            products[3] = { "ProductID": 3, "Name": "BB Ball Bearing", "ProductNumber": "BE-2349" };

            products[4] = { "ProductID": 4, "Name": "Headset Ball Bearings", "ProductNumber": "BE-2908" };

where the key to the array is the associated productid, instead of just its index.  Either way is equally valid in javascript, but when I try it this way instead of the first way, I get an exception saying:

Microsoft JScript runtime error: There was an error parsing the array data and applying the defined data schema: Unable to get value of the property 'ProductID': object is null or undefined

and if I look at it in the debugger it is because it is trying to get it for data[0] instead of data[1] .  Seems like maybe datasource is doing (for i = 0; i < data.length; i++) when it should instead be doing (for row in rows) - could this be fixed???

The reason that I would want to do this is that I have several tables with alot of data in them, and I'd like to be able to navigate between them by primary key without having to iterate the whole table to find the item I'm interested in when I navigate.