0

Hi I have 2 variants of code both do not work. My problem is I want to pass an argument into handler of addBinding method. console.log(x) returns as it should be but when it is passed into handler problem is that that the argument for that function is same for all of the bindings and I want to have it different base on tagValue (tagValue = argument I want in the function). What is wrong? Posting a 2 variants of code (good to mention that for example key is linked without any problem only handler have problems):

     for (j = 0, len = ref1.length; j < len; j++) {
      tag = ref1[j];
      if (tag.key !== void 0) {
        tagValue = name + "/" + tag.label;
        tagKey = tag.key;
        tagg = tag.label;
        x = "this.onTagHotkey('" + ("" + tagValue) + "');";
        console.log(x);
        map.addBinding({
          key: "" + tagKey,
          scope: this,
          handler: function() {
            return eval(x);                                           #problem here
          }
        });
        console.log(map);
      }

or

     for (j = 0, len = ref1.length; j < len; j++) {
      tag = ref1[j];
      if (tag.key !== void 0) {
        tagValue = name + "/" + tag.label;
        tagKey = tag.key;
        tagg = tag.label;
        map.addBinding({
          key: "" + tagKey,
          scope: this,
          handler: function() {
            return this.onTagHotkey(tagValue);                       #problem here
          }
        });
        console.log(map);
      }
Reporter
  • 3,897
  • 5
  • 33
  • 47
vejce4
  • 11
  • 2
  • could you add a fiddle (https://fiddle.sencha.com) so that it is easier to help? – Dinkheller Feb 16 '22 at 18:43
  • Hi it is not possible since this is a big application connected to many things. – vejce4 Feb 17 '22 at 08:24
  • Without any further information I would have to take a wild guess. Map is a Goolge Map and you are trying to add keypress functionality. The tagKey is some key from the currently selected item. You see I definately need more information, on what you are trying to achive. What is map, tag, and which component type are you trying to bind. – Dinkheller Feb 17 '22 at 10:29

0 Answers0