如何将嵌套模型与主干表单列表一起使用?我想使用自定义模板制作一个嵌套模型,但这给出了一个错误:"未定义的渲染"
我想使用自定义模板通过骨干表单制作视图。模板是
<div class="container-fluid add-apikey" data-class="add-apikey">
<div class="page-head">
<h2>API Key</h2>
</div>
<div class="cl-mcont">
<div class="row">
<div class="col-sm-12">
<!-- New Zone -->
<div class="block-flat">
<form class="form-horizontal" role="form">
<div class="header">
<h3>Create New API Key</h3>
</div>
<div class="content">
<div class="formAlerts"></div>
<div class="formconfirm"></div>
<div class="required" data-fields="apiName">
</div>
<div class="required" data-fields="notes">
</div>
<div class="required" data-fields="weapons">
</div>
<div class="form-group editmode">
<div class="col-sm-offset-3 col-sm-9">
<button class="btn btn-primary readOnlySave" type="button">Generate Key</button>
<button class="btn btn-default readOnlyCancel">Cancel</button>
</div>
</div>
</div>
</form>
</div>
</div>
<!-- end new zone -->
</div>
</div>
而 js 是
//Add api keys
var //util
util = require('./../../../util/util.js'),
apiKeyAddTpl = require('./../templates/apikeyadd.hbs'),
backboneFormList = require('backboneFormsList'),
backboneFormsModal = require('backboneFormsModal');
module.exports = Backbone.Form.extend({
template: apiKeyAddTpl,
schema: {
apiName: {
type: 'Text',
fieldClass: "field-apiName form-group",
editorClass: "form-control editmode"
},
notes: {
type: 'List',
fieldClass: "field-notes form-group",
editorClass: "form-control editmode"
},
weapons: {
type: 'List',
itemType: 'Object',
fieldClass: "field-weapon form-group",
editorClass: "form-control editmode",
subSchema: {
id: 'Number',
name: {
type: 'Text'
}
}
}
}
});
但是当我想在武器下添加一个字段时,这给了我一个错误。错误是:无法读取未定义的属性"渲染"。
您需要扩展视图:Backbone.View.extend
。此视图具有el
属性。您必须将此属性与form
相关联。视图具有可以重写的方法render
。文档:骨干视图