Javascript 下划线.js模板表单字段不';不要屈服

Javascript 下划线.js模板表单字段不';不要屈服,javascript,forms,backbone.js,underscore.js,Javascript,Forms,Backbone.js,Underscore.js,我在测试我所有的申请表提交时遇到了一个小问题。这是一个带有下划线的主干应用程序 我注意到,在两个有循环的表单上,当按下submit按钮时,这些循环中的表单字段不会发送。我不知道为什么 下面是一个提交表单的示例 <form role="form" action="" method="POST" id="voters-guide-survey"> <div class="row"> <div class="col-xs-4">

我在测试我所有的申请表提交时遇到了一个小问题。这是一个带有下划线的主干应用程序

我注意到,在两个有循环的表单上,当按下submit按钮时,这些循环中的表单字段不会发送。我不知道为什么

下面是一个提交表单的示例

<form role="form" action="" method="POST" id="voters-guide-survey">
    <div class="row">
        <div class="col-xs-4">
            Candidate #: <strong><%= candidate.id %></strong>
        </div>
        <div class="col-xs-4">
            Name: <strong><%= candidate.firstName %> <%= candidate.lastName %></strong>
        </div>
    </div>

    <hr />

    <div class="row">
        <div class="col-xs-12">
            <p>The following are 5 policy statements dealing with issues in the news. Please check the option that best reflects your point of view.</p>
        </div>
    </div>

<% _.each(questions, function(questionData) { %>
    <div class="row">
        <div class="form-group col-xs-8">
            <%= questionData.question %><br />
            <input type="hidden" name="question-<%= questionData.id %>" value="<%= questionData.question %>" />
            <span class="error" for="survey-question-<%= questionData.id %>"></span>
        </div>
    </div>

    <div class="row">
        <div class="form-group col-xs-6">
            <% _.each(questionData.options, function(option) { %>
            <label class="radio-inline"><input type="radio" name="survey-question-<%= questionData.id %>" value="<%= option.name %>" required /> <%= option.name %></label><br />
            <% }); %>
        </div>
    </div>
<% }); %>

    <hr />

    <div class="row">
        <div class="form-group col-xs-4 col-xs-offset-4">
            <input type="hidden" name="numQuestions" value="<%= questions.length %>" />
            <% if (pageStatus == 'disabled') { %>
            <a href="javascript:void(0);" path="questionnaire/endorsements" candidate-id="<%= candidate.id %>">Continue to Next Page &raquo;</a>
            <% } else { %>
            <input type="hidden" name="id" value="<%= candidate.id %>" />
            <input type="hidden" name="page" value="endorsements" />
            <input type="submit" name="save-questionnaire" value="Submit and Continue" />
            <% } %>
        </div>
    </div>
</form>
下划线模板的工作原理是否有我遗漏的地方

单击submit按钮时,传递到的唯一数据是循环之外的内容,因此只有末尾的隐藏字段


我该怎么做呢?

天哪,我有时候真傻。它与下划线无关,也与我的字段名中包含连字符这一事实无关。我忘了我必须还原一些表单文件,忘了更改hypens


抱歉这么愚蠢

如果字段名中有连字符,会产生什么问题?除了以字母开头外,我认为没有任何规则。下划线本身不会引起任何问题,但当我在字段名称中使用连字符而不是下划线时(即
,以这种方式收集表单时,元素不会显示:
$('form#form id')。serializeObject()
我以前遇到过这个问题,我认为我已经以各种形式解决了它,但显然我错过了一些。
    {
    "questions": [
        {
            "id": 1,
            "question": "Question 1",
            "options": [
                {"id": 1, "name": "Strongly agree"},
                {"id": 2, "name": "Somewhat agree"},
                {"id": 3, "name": "Have mixed feelings"},
                {"id": 4, "name": "Somewhat disagree"},
                {"id": 5, "name": "Strongly disagree"},
                {"id": 6, "name": "Have no opinion"},
                {"id": 7, "name": "Do not wish to respond"}
            ],
            "answer": ""
        },
        {
            "id": 2,
            "question": "Question 2",
            "options": [
                {"id": 1, "name": "Strongly agree"},
                {"id": 2, "name": "Somewhat agree"},
                {"id": 3, "name": "Have mixed feelings"},
                {"id": 4, "name": "Somewhat disagree"},
                {"id": 5, "name": "Strongly disagree"},
                {"id": 6, "name": "Have no opinion"},
                {"id": 7, "name": "Do not wish to respond"}
            ],
            "answer": ""
        },
        {
            "id": 3,
            "question": "Question 3",
            "options": [
                {"id": 1, "name": "Strongly agree"},
                {"id": 2, "name": "Somewhat agree"},
                {"id": 3, "name": "Have mixed feelings"},
                {"id": 4, "name": "Somewhat disagree"},
                {"id": 5, "name": "Strongly disagree"},
                {"id": 6, "name": "Have no opinion"},
                {"id": 7, "name": "Do not wish to respond"}
            ],
            "answer": ""
        },
        {
            "id": 4,
            "question": "Question 4",
            "options": [
                {"id": 1, "name": "Strongly agree"},
                {"id": 2, "name": "Somewhat agree"},
                {"id": 3, "name": "Have mixed feelings"},
                {"id": 4, "name": "Somewhat disagree"},
                {"id": 5, "name": "Strongly disagree"},
                {"id": 6, "name": "Have no opinion"},
                {"id": 7, "name": "Do not wish to respond"}
            ],
            "answer": ""
        },
        {
            "id": 5,
            "question": "Question 5",
            "options": [
                {"id": 1, "name": "Strongly agree"},
                {"id": 2, "name": "Somewhat agree"},
                {"id": 3, "name": "Have mixed feelings"},
                {"id": 4, "name": "Somewhat disagree"},
                {"id": 5, "name": "Strongly disagree"},
                {"id": 6, "name": "Have no opinion"},
                {"id": 7, "name": "Do not wish to respond"}
            ],
            "answer": ""
        }
    ]
}