0

出于某种原因,我无法让我的全局变量 counter 增加,即使它在函数内增加,我也有 count++ 发生。我的输出结果在函数内输出的文本和函数外的文本之间是不同的。知道我在这里做错了什么吗?在survey.oncomplete函数结果的每次迭代中计数不应该增加吗?

Survey
    .StylesManager
    .applyTheme("modern");

var kn2 = "LwrHXqFRN_pszCopTKHF_Q"
var kn3 = "exroCUoYl4wVzs7pKU_49w"

var count = 0

var keyname = ("kn" + count)

var mapilink = "https://images.mapillary.com/" + (keyname) + "/thumb-1024.jpg";

var json = {
 pages: [
  {
   name: "page1",
   elements: [
    {
     type: "image",
     name: "image",
     imageLink: (mapilink),
     imageHeight: 580,
     imageWidth: 640
    },
    {
     type: "html",
     name: (keyname),
     visible: false,
     html: (keyname)
    },
    {
     type: "rating",
     name: "Walkability",
     title: "How walkable does this look to you"
    },
    {
     type: "rating",
     name: "Saftey",
     title: "How safe does this look to you"
    },
    {
     type: "rating",
     name: "Comfortability",
     title: "How comfortable does this look to you"
    }
   ]
  }
 ]
}

window.survey = new Survey.Model(json);

var username = document.getElementById("user").value;

survey
    .onComplete
    .add(function (result) {
        count ++;
        var PID = document.getElementById("user").value;
        var results = PID + "_" + (keyname) + ":\n" + JSON.stringify(result.data, null, 3) + (count) ;
        document
            .querySelector('#surveyResult')
            .textContent = results;
    survey.clear();
    survey.render();
    });

$("#surveyElement").Survey({model: survey});
4

1 回答 1

0

从单独的 stackexchange 帖子中得到了答案 - 基本上,我需要将所有内容包装在更多功能中。

函数输出函数文本而不是预期的输出

于 2020-12-09T01:23:38.637 回答