0

我在点击链接上使用 Json2hTML 库我想调用一个函数。但它不起作用

var data = [{
  "testSuite": [{
        "testCase": [{
          "testCaseName": "tc1",
          "testCaseResult": "false",
          "testCaseScreenShot": "imageofTestCase",
          "testStep": [

              {
                "testStepResult": "true",
                "testStepName": "ts1",
                "testStepScreenShot": "image"
              }, {
                "testStepResult": "true",
                "testStepName": "ts2",
                "testStepScreenShot": "image"
              }, {
                "testStepResult": "false",
                "testStepName": "ts3",
                "testStepScreenShot": "image"
              }
            ] //End of TestStep
        }, ], // End of testSuite1
        "testSuiteName": "GoogleTestSuite",
        "testSuiteResult": "false",
        "testSuiteScreenShot": "image"
      },

    ] //End of TestSuite JSON 
}];

html库:

 var transform = {
     "testSuite": {

       "tag": "ul",
       "class": "report",
       "children": [{
         "tag": "a",
         "href": "#testSuiteLink",
         "children": [{
           "tag": "font",
           "color": function() {
             if (data[0].testSuiteInformation[0].testSuiteResult == "true") {
               return "green";
             } else {
               return "red";
             }
           },
           "onclick": function() {
             $(".getTestStepClass").toggle();
           },
           "children": function() {

             return (json2html.transform(this.testSuite, transform.getTestSuiteName));
           }
         }]
       }]
     },
     "getTestSuiteName": {
       "tag": "li",
       "id": "testSuiteLink",
       "class": "getTestSuiteNameClass",
       "html": "${testSuiteName}",
       "onclick": function() {
         //This function is not being called
         * *
         return ('<ul>' + json2html.transform(this.testCase, transform.testCase) + '</ul>'); * *

       },

     },

     "testCase": {
       "tag": "li",
       "class": "testCaseNameClass",
       "children": [{
           "tag": "font",
           "color": function() {
             if (this.testCaseResult == "true") {
               return "green";
             } else {
               return "red";
             }
           },
           return (json2html.transform(this, transform.getTestCaseName));
         }
       }]

   },

   "getTestCaseName": {
     "tag": "ul",
     "class": "getTestCaseNameClass",
     "html": "${testCaseName}",
     "id": "testCaseLink",
     "children": function() {
       return (json2html.transform(this.testStep, transform.testStep))
     },

   },

   "testStep": {
     "tag": "ul",
     "class": "testStepClass",
     "children": function() {
       return (json2html.transform(this, transform.getTestStep));
     }

   },

   "getTestStep": {
     "tag": "li",
     "class": "getTestStepClass",
     "children": [
       //Apply font color for result of testSuite
       {
         "tag": "font",
         "color": function() {
           if (this.testStepResult == "true") {
             //flag=flag+1;
             return "green";
           } else {
             return "red";
           }
         },

         "html": "${testStepName}",
         "children": function() {
           if (this.testStepResult == "false")
             return ('<ul>' + json2html.transform(this, transform.testStepResultDescription) + '</ul>');

         }
       }
     ]

   },


   "testStepResultDescription": {
     "tag": "li",
     "class": "testStepResultDescriptionClass",
     "children": [{
       "tag": "div",
       "html": "${testStepScreenShot}",
     }]
   },
   "testCaseResultDescription": {
     "tag": "li",
     "children": [{

       "tag": "div",
       "html": "${testCaseScreenShot}",
     }]
   }
 };

预期输出:

GoogleTestSuite(点击此链接应显示以下内容)

  • Tc1(函数结果)
  • Tc2(函数结果)
4

0 回答 0