代码之家  ›  专栏  ›  技术社区  ›  ftdeveloper

JSON对象中的Send函数(带参数)

  •  0
  • ftdeveloper  · 技术社区  · 6 年前

    首次触发 packtNs.graduateForm.loadEvent packtNs.common.populateWithTodaysDate("packt_supervisor", "packt_postgraduatestartdate") 函数到 packtNs.common.wireOnChangeEvents 功能。

    这是我的密码:

    var packtNs = packtNs || {};
    
    packtNs.common = packtNs.common || {};
    
    /**
    * A method that populates the post graduate start date
    * when the supervisor lookup is populated.
    * @returns {Void}
    */
    
    packtNs.common.populateWithTodaysDate = function(attributeToMonitor, dateAttributeToChange)
    {
        console.log("Populatewithtodaysdate function triggered");
    }
    
    packtNs.common.wireOnChangeEvents =
        function(eventAttributeTuples){
            debugger;
            for (var i in eventAttributeTuples) {
               console.log(eventAttributeTuples[i].attribute);
               ////attribute is OK
               console.log(eventAttributeTuples[i].function);
               ////function is always undefined. eventAttributeTuples[0] object doesnt have function - tried different names
            }
    
    }
    
    packtNs.graduateForm = packtNs.graduateForm || {};
    
    packtNs.graduateForm.loadEvent = function(){
        packtNs.common.wireOnChangeEvents([
            { 
                attribute: "packt_supervisor",
                function:packtNs.common.populateWithTodaysDate("packt_supervisor", "packt_postgraduatestartdate")
            }
        ]);
        debugger;
    }
    
    2 回复  |  直到 6 年前
        1
  •  1
  •   Mark Schultheiss    6 年前

    这是一个名称间隔的对象,不是JSON,但是要获得一些东西,必须返回一些东西。我把你的“功能”改名为“神话”,因为它错了。

    var packtNs = packtNs || {};
    
    packtNs.common = packtNs.common || {};
    
    /**
     * A method that populates the post graduate start date
     * when the supervisor lookup is populated.
     * @returns {Void}
     */
    
    packtNs.common.populateWithTodaysDate = function(attributeToMonitor, dateAttributeToChange) {
      console.log("Populatewithtodaysdate function triggered");
      return {
        arg1: attributeToMonitor,
        arg2: dateAttributeToChange
      };
    }
    
    packtNs.common
      .wireOnChangeEvents = function(eventAttributeTuples) {
        //debugger;
        console.log("tup:", eventAttributeTuples);
        for (var i in eventAttributeTuples) {
          console.log(eventAttributeTuples[i].attribute);
          ////attribute is OK
          console.log(eventAttributeTuples[i].mything);
          ////function is always undefined. eventAttributeTuples[0] object doesnt have function - tried different names
        }
        return eventAttributeTuples;
      }
    
    packtNs.graduateForm = packtNs.graduateForm || {};
    
    packtNs.graduateForm.loadEvent = function() {
      return packtNs.common.wireOnChangeEvents([{
        attribute: "packt_supervisor",
        mything: packtNs.common.populateWithTodaysDate("packt_supervisor", "packt_postgraduatestartdate")
      }]);
      // debugger;
    }
    
    var myresult = packtNs.graduateForm.loadEvent();
    console.log("myresult:",myresult);
        2
  •  1
  •   Robert Gardziński    6 年前

    首先,正如在您的问题下面的注释中指出的,将属性名从“function”更改为其他名称。然后我建议您尝试将传递的字符串表示形式的函数调用到eval方法中(请参见: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval )