2014-11-25 33 views
3

如何在骨幹表單列表中使用嵌套模型?我想用一個自定義模板創建一個嵌套模型,但是這給出了一個錯誤:「渲染未定義的」如何在骨幹表單列表中使用嵌套模型?我想用自定義模板製作一個嵌套模型

我想通過使用自定義模板的主幹窗體進行視圖。模板是

<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' 
       } 
      } 
     } 
    } 

}); 

但是,這是給我一個錯誤,當我想下的武器添加一個字段。 錯誤是:無法讀取未定義的屬性'呈現'。

回答

0

您需要擴展一個View:Backbone.View.extend。該視圖具有el屬性。您必須將此屬性與form關聯。視圖有一個方法render,你可以覆蓋。 Doc:backbone view