2014-10-02 40 views
0

如何定義爲CompositeViewTemplateNotFoundError:無法呈現,因爲模板的錯誤,null或undefined

define(function (require) { 

    "use strict"; 

    var _   = require('underscore'), 
     Marionette = require('backbone.marionette'), 
     Row  = require('app/views/Dam/row'), 
     tpl  = require('text!tpl/Dam/table.html'), 
     template = _.template(tpl); 

    return Marionette.CompositeView.extend({ 

     tagName: "table", 

     className: "table table-bordered", 

     initialize: function (opt) { 
      this.ev = opt.ev; 
     }, 

     childView: Row, 

     childViewContainer: function(){ 
      return "tbody" 
     }, 

     childViewOptions: function (model, index) { 
      return { 
       ev: this.ev 
      } 
     }, 

     onRender: function() { 
      this.ev.trigger('App:Loading:Hide', true); 
     } 

    }); 

}); 

模板這是CompositeView中的Marionette.Region一個孩子。我只是像這樣觸發它region.show(new CompositeView)。我正在使用最新的Backbone以及木偶。

+0

您需要添加模板。閱讀[this](http://marionettejs.com/docs/marionette.compositeview.html)。 – 2014-10-02 11:32:00

+0

我跟隨[這](http://marionettejs.com/docs/marionette.compositeview.html#compositeviews-childviewcontainer),但我用requirejs加載模板 – Muhaimin 2014-10-03 02:11:18

回答

1

爲你的任何視圖

Marionette.CompositeView.extend({ 

     tagName: "table", 
     template : tpl, 
     ..... 
     ..... 

定義模板,它應該工作

+0

它變成另一個錯誤:'UndefinedTemplateError:無法呈現,因爲它的模板爲空或未定義。「 – Muhaimin 2014-10-03 01:18:01

+0

您確定:tpl/Dam/table.html存在嗎?如果你使用chrome或firebug進行調試,並且觀看「tpl」會給你帶來什麼?如果它爲空那麼這就是你必須修復的問題 – 2014-10-03 13:09:33

+0

對不起,這些錯誤實際上屬於我的itemView – Muhaimin 2014-10-03 15:10:48