How do I properly store a javascript template, so that it isn't instantiated multiple times

后端 未结 6 384
一整个雨季
一整个雨季 2021-02-03 12:44

I\'m using Backbone and therefore Underscore to render my templates. My templates get rendered in

6条回答
  •  梦谈多话
    2021-02-03 12:56

    Most Backbone examples I've seen do it like this. This will only traverse the DOM once to parse the template when the page finishes loading and use that for each new ItemView().

    App.ItemView = Backbone.View.extend({
        template: _.template($("#ItemTemplate").html()),
    
        className:'well',
    
        events: {
            'click .continue': 'handleContinueClick',
        },
    
        ...
    });
    

    http://backbonejs.org/docs/todos.html#section-21

提交回复
热议问题