Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The existing structure used an Object as a cache where the keys are the values of option elements, and values are the HTML content of the option elements. In Javascript, if a numeric value in the form of a string is assigned as a key, it gets converted to an integer. Optimization routines would then order the object to ensure faster access to elements. For example: cache = {} cache['2'] = "two" cache['1'] = "one" console.log(cache[2]) #=> "two" console.log(cache[1]) #=> "one" console.log(cache) #=> {1: "one", 2: "two"} Note the coercion of strings to ints above. This messes with the ordering of multiselect options list whenever there is a user input. To avoid this from happening, the keys need to have a string that can't be coerced automatically, and then preserve the value of the option element. I chose to use an object that stores the option value and the option HTML as the value of the cache and a string of the format 'o_<option value>' as the key. This ensures that the insertion order is preserved. This is the new structure: cache = { 'o_271': { id: 271, value: 'CartItem #271'}, 'o_270': { id: 270, value: 'CartItem #270}' }
- Loading branch information