-1

我正在从表单中提交的数据中构建一个 JSON 数组,但是这个脚本正在破坏,无法弄清楚是什么原因造成的!

有任何想法吗?

查询:

    var canvas = [];

    var Submission = {};

    var Answer = {};

        $('.question-holder > input').each(function(){
        answer = $(this).val()
        input_name = $(this).attr('name')
        label = $(this).closest('li').find('label')

        // Push everything into the questions array
        Answer.push({
        Answers: answer,
        Input_Name: input_name,
        Label: label
        });         

        });

        $('.submit-holder > input').each(function(){
            answer = $(this).val()
            input_name = $(this).attr('name')
            label = $(this).closest('li').find('label')

            Submission.push({
            Question: label,
            Input_Name: input_name,
            Submitted_data: answer
            });                         
        });

        canvas.push({
        Submission: Submission,
        Answers: Answer,
        Motivation: $('.motivation').val()
        });

        json = JSON.stringify({json: canvas}, null, "\t");  
4

1 回答 1

2

与声明有关的问题:

var Submission = {};
var Answer = {};

它们应该是这样的数组,对象(哈希)没有push()定义

var Submission = [];
var Answer = [];
于 2013-08-21T23:32:02.113 回答