首页 文章

javascript中似乎不存在的循环引用错误

提问于
浏览
0

在这一次我一直在摸不着头脑 . 不知道 .

我有一个函数,它返回一个javascript对象,准备传递给JSON.stringify函数 . 当我这样做时,我得到一个循环引用错误 . 看来'callWidget'方法正在返回一个我不想要的匿名函数 . 我只是没有看到错误 .

function putAnswersTogether() {
    var answers = [];

    $(".addedquestion").each(function(i, e) {

      var answerJSON = {qname: $(e).find(".questionname").val(),
          answerid: $(e).attr("answerid"),
          answer: callWidget($(e), "getResponse", "")};

      answers.push(answerJSON);
    });

    return answers;
  }
  
function callWidget(questioncontroldiv, method, value) {
	var divtype = $(questioncontroldiv).attr('id');
	var result;
	switch(divtype) {
	case "mogrify-multiplechoice":
		result = $(questioncontroldiv).multiplechoice(method, value);
		break;
	case "mogrify-checkbox":
		result =  $(questioncontroldiv).checkbox(method, value);
		break;
	}
	return result;
}

// The following methods are contained within widgets for multiplechoice and checkbox

_getResponseJSON: function() {
    var qname = this._getQuestionName();
	var answers = [];
			
    this.options.questioncontrol.find(
      "input[name='optradio-" +
      qname +
      "']:checked"
    ).each(function(i,e) {
        answers.push($(e).val());
    });
    
    return answers;
  },

_getResponseJSON: function() {
    qname = this._getQuestionName();
    var answer = this.options.questioncontrol
        .find("input[name='optradio-" + qname + "']:checked")
        .val();
			
	return answer;		
},

1 回答

  • 0

    您已经将函数 putAnswersTogether 中的jQuery对象传递给 callWidget

    answer: callWidget($(e), "getResponse", "")
    

    所以从 callWiget funciton中删除jQuery标签

    var divtype = $(questioncontroldiv).attr('id');
    

相关问题