underscore.js nested templates

后端 未结 4 572
不思量自难忘°
不思量自难忘° 2021-01-30 16:11

Is it possible to somehow take a DOM element from a underscore template and use it as another template?

The idea is that my app needs to render a document that contains

4条回答
  •  庸人自扰
    2021-01-30 17:01

    You can pass the nested template as a variable in the template assignments to the main template, e.g.:

    HTML:

    
    
    
    

    JS:

     var renderSub = _.template( $('#sub_template').remove().text() ),
         renderMain = _.template( $('#main_template').remove().text() );
    
      renderMain({num:5, renderSub:renderSub});
    

提交回复
热议问题