> for(var key in jsonObject) { > addSelectOption(groupSelect, jsonObject[key], key, false);
jsonObject is a hash, the keys in the hash are not stored with a predictable ordering. If you want an ordered list then you should create an array. On Thu, May 15, 2008 at 3:58 AM, Leon Derks <[EMAIL PROTECTED]> wrote: > Thanks Chris, > > That worked. > The only thing is that the order of groups in the select is gone. > I know for sure I put them in the correct order in the java jsonObject. > I think the var jsonObject = response.evalJSON(); or the for(var key in > jsonObject) messes up the order. > Is there a way to solve this? > > For the ones interested, I fill my select box now in this way: > > Java Page: > @OnEvent(component = "productSelect", value = "change") > JSONObject onProductSelectChanged(String value) { > ProductCategory category = > ProductCategory.getProductCategoryByName(value); > groups = characteristicDAO.findGroupsByProductCategory(category); > JSONObject jsonObject = new JSONObject(); > for (CharacteristicGroup group : groups) { > Long id = group.getId(); > jsonObject.put(id.toString(), group.getName()); > } > return jsonObject; > } > > javascript: > function productSelectChanged(response) { > var groupSelect = $('groupSelect'); > clearSelectOption(groupSelect); > var jsonObject = response.evalJSON(); > for(var key in jsonObject) { > addSelectOption(groupSelect, jsonObject[key], key, false); > } > } > > Chris Lewis wrote: >> >> Try: >> >> for (var i in object) {} >> >> Where object would be your json object. >> >> Leon Derks wrote: >> >>> >>> Hi Sven, >>> >>> I only see that they get the value by using the key name. >>> For example this: >>> >>> |var data = '{ "name": "Violet", "occupation": "character" }'.evalJSON(); >>> data.name; //prints Violet. >>> | >>> >>> But in my case, I don't know the key name, so I can't get the value. >>> Is there a way to get the key names of a JSON Object? >>> For example something like this: >>> | >>> data.keys; //returns {name, occupation}| >>> >>> | >>> | >>> >>> Leon >>> >>> >>> Sven Homburg wrote: >>> >>>> >>>> http://www.prototypejs.org/learn/json >>>> >>>> 2008/5/15 Leon Derks <[EMAIL PROTECTED]>: >>>> >>>> >>>>> >>>>> Hello >>>>> >>>>> I have a JSON object like this: >>>>> >>>>> JSONObject obj = new JSONObject(); >>>>> >>>>> obj.put(entity.getId(), entity.getName()); >>>>> >>>>> But how can I get the value from my json object in javascript, if I >>>>> don't >>>>> know the key name? >>>>> >>>>> Is there a way to get the key name(s) from a json object in javascript? >>>>> >>>>> Leon >>>>> >>>>> --------------------------------------------------------------------- >>>>> To unsubscribe, e-mail: [EMAIL PROTECTED] >>>>> For additional commands, e-mail: [EMAIL PROTECTED] >>>>> >>>>> >>>>> >>>> >>>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [EMAIL PROTECTED] >>> For additional commands, e-mail: [EMAIL PROTECTED] >>> >>> >>> >> >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- -- TheDailyTube.com. Sign up and get the best new videos on the internet delivered fresh to your inbox. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]