我在运行时使用 HTTP POST 请求获取以下 JSON:
{"d": {"Result":"OK","Records": [{
"Id":1,
"QText":"Explain marketing and the usage of Marketing in short",
"AText":"demo answer",
"Marks":11,
"Comment":"no comments"
}, {
"Id":14,
"QText":"How Marketing affects SCM",
"AText":"hi",
"Marks":10,
"Comment":"No comments"
}, {
"Id":15,
"QText":"Explain Marketing Tools",
"AText":"ans 3",
"Marks":8,
"Comment":"No comments"
}, {
"Id":16,
"QText":"Pls answer this question",
"AText":"ans 4",
"Marks":0,
"Comment":"poor"
}]}}
所以现在使用 jQuery 模板插件,我生成了以下类型的 UI:
我使用下面的 jQuery 代码来创建上面的 UI:
<script id="solutionTemplate" type="text/x-jQuery-tmpl">
<div class="filtering">
<h2> Question </h2>
<div> ${QText} </div><br/>
<h2> Answer </h2>
<div> ${AText}</div><br/>
<table><tr><td>
<h2> Marks </h2>
<div>
<select id="ddlMarks-${Id}">
<option value="11" ${IsSelected(Marks,11)}>Not Checked</option>
<option value="0" ${IsSelected(Marks,0)}> Zero </option>
<option value="1" ${IsSelected(Marks,1)}> One </option>
<option value="2" ${IsSelected(Marks,2)}> Two </option>
<option value="3" ${IsSelected(Marks,3)}> Three </option>
<option value="4" ${IsSelected(Marks,4)}> Four </option>
<option value="5" ${IsSelected(Marks,5)}> Five </option>
<option value="6" ${IsSelected(Marks,6)}> Six </option>
<option value="7" ${IsSelected(Marks,7)}> Seven </option>
<option value="8" ${IsSelected(Marks,8)}> Eight </option>
<option value="9" ${IsSelected(Marks,9)}> Nine </option>
<option value="10" ${IsSelected(Marks,10)}> Ten </option>
</select>
</div></td>
<td><h2> Comments </h2>
<textarea id="textarea-${Id}" cols="120" rows="1"> ${Comment} </textarea>
</td>
<td><br/><input type="button" id="btn-${Id}" value="Submit"/></td>
</tr></table>
</div>
</script>
这是另一个用于将获取的数据绑定到 jQuery 模板的代码片段
if (response.d['Result'] == 'OK') {
var solutionList = response.d['Records'];
$('#solutionTemplate').tmpl(solutionList).appendTo('#divAnswers');
}
如您所见,现在的问题是 UI 中的提交按钮。使用该提交按钮,我必须将该特定块(问题)的更新数据发布到服务器。如何确定按下了哪个提交按钮,以及如何获取仅与该特定提交按钮相关的文本框/下拉列表的数据?