與現有 HTML 繫結的檢視

假設頁面中包含以下 HTML:

<body>
    <div id="myPage">
    </div>
</body>

檢視可以繫結到它:

var MyPageView = Backbone.View.extend( {
    "el": "#myPage",
    "template": _.template( "<p>This is my page.</p>" ),

    "initialize": function(){
        this.render();
    },

    "render": function(){
        this.$el.html( this.template() );
    }
} );

new MyPageView();

瀏覽器中的 HTML 現在將顯示:

<body>
    <div id="myPage">
        <p>This is my page.</p>
    </div>
</body>