0

嗨,我有 2 个代码变体都不起作用。我的问题是我想将参数传递给 addBinding 方法的处理程序。console.log(x) 按原样返回,但是当它传递给处理程序时,问题是该函数的参数对于所有绑定都是相同的,我希望它基于 tagValue 不同(tagValue = 我想要的参数在函数中)。怎么了?发布 2 种代码变体(值得一提的是,例如键链接没有任何问题,只有处理程序有问题):

     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);
      }

或者

     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);
      }
4

0 回答 0