javascript dict.get something::else?

    Sep 25 2012 | 12:07 pm
    I can't tell if this is exactly the same issue as discussed here so apologies for duplication.
    I am trying to access one of my dictionaries in JavaScript. At the moment it's a bunch of conversion tables that seemed easier to put in a single dictionary but this is something that I anticipate doing a lot, as I do in regular patches. Am I doing something wrong or is this a bug?
    Essentially when I attempt myDictionary.get("level1::level2") as formatted for replace in the help file I get a jsobject where I would expect to see the value. Example below.
    contents of getting.js:
    conversions = new Dict("conversions");
    test = new Dict();
    post (conversions.getkeys(),"n");
    //all seems to work as expected
    path = "something";
    post (path, ":", conversions.get(path),"n");
    path = "kepToVG";
    post (path, ":", conversions.get(path),"n");
    //this is what I'm trying to avoid but it's a workaround
    test = conversions.get(path);
    //going down one level futher
    path = "kepToVG::q";
    //replacing as in the help file seems to work fine
    conversions.replace(path, "testing");
    // am I doing something wrong here? I would expect to see the value
    post (path, ":", conversions.get(path),"n");

    • Sep 25 2012 | 3:57 pm
      i believe these issues are related to javascript behavior that will return an object instead of an array, if the array only contains a single element.
      see if this code helps:
      function dict_to_jsobj(dict) {
      	var o = new Object();
      	var keys = dict.getkeys();
      	if (keys instanceof Array) {
      		for (var i = 0; i < keys.length; i++)
      			var value = dict.get(keys[i]);
      			if (value && value["push_to_coll"]) {
      				value = dict_to_jsobj(value);
      			o[keys[i]] = value;
      	} else {
      		var value = dict.get(keys);
      		o[keys] = value;
      	return o;
    • Sep 25 2012 | 4:36 pm
      Thanks for your reply. I think I have an idea of what's going on, but I'm not entirely sure if I understand how to implement - do you mean for me to use that function directly, perhaps like this? Using code above as example as that's where I've just copied and tested it:
      path = "kepToVG::w";
      output = conversions.get(path);
      post (path, ":", dict_to_jsobj(output),"n");
    • Sep 30 2012 | 11:17 am
      function bang()
      var dict_conversions = new Dict("conversions");
      if (dict_conversions.contains("kepToVG"))
      var obj = dict_conversions.get("kepToVG");
      if (obj instanceof Dict)
      var data = obj.get("q");
      post("q: ", data, "n");
    • Oct 02 2012 | 9:28 pm
      Thanks both for your help. I'm still struggling with this problem and wondering if you'd be able to clarify further.
      I've tried looking at the first suggestion but either it hasn't worked out or I haven't been able to figure out how to use or adapt it. Please could you let me know?
      I'm still not actually sure if I'm supposed to be able to use dict.get with an argument formatted like so:
      I've been playing around a bit and trying to work out where it might be going wrong and have come up with the attached patch, just looking at where the process ends up by looking at the type and the keys if it is a dictionary. Rather than the result I'm expecting, it appears to be returning a reference to the dictionary containing it.
    • Nov 26 2012 | 6:36 pm
      Just bumping this thread as I still haven't managed to resolve it and struggling to move forward with the project - could anyone give any advice please?
    • Mar 17 2017 | 6:01 am
      In spite of the four years passed, this maybe useful for someone having the same issue:
      function fetch(a,b){
      var dict_conversions = new Dict("conversions");
      var keys = dict_conversions.getkeys();
      post("keys: ", keys, "\n");
      if (dict_conversions.contains(keys[a])) {
      post("key: ", keys[a], "\n");
      var obj = dict_conversions.get(keys[a]);
      if (obj instanceof Dict) {
      var subkeys = obj.getkeys();
      post("subkeys: ", subkeys, "\n");
      var data = obj.get(subkeys[b]);
      post("data: ", data, "\n");