Run Template in Template (recursion) within underscore.js template engine

前端 未结 5 497
深忆病人
深忆病人 2020-12-30 02:59

I am using backbone.js and underscore.js to build an javascript application. Since hours of reading and trying to run a template within a template like below, it is getting

5条回答
  •  鱼传尺愫
    2020-12-30 03:50

    I implemented this recently using backbone-relational. I created a fiddle that I thought might be helpful if you want to see a working solution: http://jsfiddle.net/blaisco/ADKrK/

    I've posted the relevant bits below.

    The view:

    var FolderView = Backbone.View.extend({
        el: $("#main"),
    
        template: _.template($("#folder-tmpl").html()),
    
        render: function () {
            this.$el.html(this.template({
                "folder": parentFolder.toJSON(),
                "templateFn": this.template
            }));
            return this;
        }
    });
    

    The html/template:

    提交回复
    热议问题