由于缺乏良好的语法,没有进入模板构建器,这有点混乱,但您可以在循环中手动构建/插入每个字段集。
我无法回答 ajax 问题,因为我不精通这方面,但以下示例应该可以帮助您入门
var ajaxForNumberOfFields,
ajaxForNumberOfDataSets,
ajaxForDataTitle,
ajaxForDataName,
$field,
$header,
$data1,
$data2;
// if the form already has old data then clear it
if(clearData) {
$('form:not(first-child)').remove();
}
// ajax the number of fields
// something like $.ajax('yourURL', options).done(function(data){ajaxForNumberOfFields = data);
for(var i=0;i<ajaxForNumberOfFields;++i) {
// create a new fieldset
$field = $('<fieldset />');
// ajax the number of data sets
// ajaxForNumberOfDataSets = $.ajax('yourURL', options).done(function(data){ajaxForNumberOfFields = data);
for(var j=0;j<ajaxForNumberOfDataSets;++j;)
// new data header and rows
$header = $('<div class=_50 />');
$data1 = ('<div class=_25 />');
$data2 = ('<div class=_25> Other: </div>');
// ajax the data for the current set
// ajaxForDataTitle = $.ajax('yourURL', options).done(function(data){ajaxForNumberOfFields = data);
// ajaxForDataName = $.ajax('yourURL', options).done(function(data){ajaxForNumberOfFields = data);
// load header
$header
.append($('<strong />').text(ajaxForDataTitle))
.append($('<input type="text" />').attr('name', ajaxForDataName));
// build data 1
$data1
.append('<label />')
.append($('<input type="radio" id="radPeri1mod" data-mini="true"/>').attr('name', ajaxForDataName))
.append('<label for="radPeri1mod">PERI-1-MOD</label>')
.append('<label />')
.append($('<input type="radio" id="radPeri1" data-mini="true"/>').attr('name', ajaxForDataname))
.append('<label for="radPeri1">PERI-1</label>');
// build data2
// iterating over fieldsets will restrict the use of the id attribute
// will need to use class attribute to locate the input, then figure out which one it is
$data2
.append($('<input type="text" class="textOther" />').attr('name', ajaxforDataName));
// build the fieldset
$field.append($header).append($data1).append(data2);
// stuff the fieldset into the form
$('form').append($field);
}
}