我试图让Marionette呈现我的JST模板,在Rails环境中工作。根据教程和Marionette官方文档,我必须重写Marionette呈现方法:
Backbone.Marionette.Renderer.render = (template, data) ->
path = JST["path/to/template/" + template]
unless path
throw "error"
path(data)当从视图调用模板时:
class myChildView extends Marionette.ItemView
template: "specific-template-location/template"
class myCompositeView extends Marionette.CompositeView
template: "specific-template-location/template"
childView: myChildView我在渲染时得到一个Uncaught error。奇怪的是,当我使用itemView而不是childView时,模板是正确呈现的。我正在使用的教程已经被证明是过时的,但我在正式文档中没有发现childView \ itemView的差异与模板声明之间的任何关联。任何提示都将不胜感激。
附加信息:I也不能直接从DOM传递模板(Marionette呈现重写已删除),即:
class myCompositeView extends Marionette.CompositeView
template: "#mytemplate"还抛出一个no template error。我传递模板的唯一方法是通过下划线模板构造函数_.template(),这至少表明将集合传递给视图没有问题。
发布于 2015-09-10 03:57:00
你可以这样做:
do (Marionette) ->
_.extend Marionette.Renderer,
lookups: ['path/to/template/apps', 'path/to/template/components']
render: (template, data) ->
return unless template
path = @getTemplate(template)
throw "Template #{ template } not found!" unless path
path(data)
getTemplate: (template) ->
for lookup in @lookups
path = "#{ lookup }/#{ template }"
return JST[path] if JST[path]https://stackoverflow.com/questions/32322686
复制相似问题