是的,这是可能的,因为backbone-forms
by powmedia 确实提供了模板选项。
您只需要构建模板,并将其作为选项传递给它。
var FormSchema = Backbone.Model.extend({
defaults: function() {
return {
'cidesc': 'abc',
'cimisc': 3555,
'codesc': 'asdf',
'comisc': 123,
'todesc': 'def',
'tomisc': 1233,
};
},
});
var Form = Backbone.Form.extend({
template: _.template($('#formTemplate').html()),
schema: {
'cidesc': { type: 'Text', title: '' },
'cimisc': { type: 'Text', title: '' },
'codesc': { type: 'Text', title: '' },
'comisc': { type: 'Text', title: '' },
'todesc': { type: 'Text', title: '' },
'tomisc': { type: 'Text', title: '' },
}
});
var form = new Form({
model: new FormSchema()
}).render();
$('body').append(form.el);
<script id="formTemplate" type="text/html">
<form>
<table>
<tbody>
<tr>
<td>Buffer check-in time</td>
<td><div data-fields="cidesc"></div></td>
<td><div data-fields="cimisc"></div></td>
</tr>
<tr>
<td>Buffer check-out time</td>
<td><div data-fields="codesc"></div></td>
<td><div data-fields="comisc"></div></td>
</tr>
<tr>
<td>Buffer check-out time</td>
<td><div data-fields="todesc"></div></td>
<td><div data-fields="tomisc"></div></td>
</tr>
</tbody>
</table>
</form>
</script>
在这里试试http://jsfiddle.net/xxhLxr7z/1/ :)