简体   繁体   中英

Backbone.js View not rendering EL

I am having a problem the Backbone.js View not rendering. My code is fairly simple and looks like this:

TableView = Backbone.View.extend({
    initialize : function() {
        this.render();
    },
    render : function() {
        var template = _.template($("#table_template").html(), {});
        alert(this.el);
        this.el.html('Go');
        //this.el.html(template);
    },
    events: {

    },
});

And this is the code for instaniting the object and setting the el

<script type="text/javascript">
            $(document).ready(function() {
                var t  = $("#table_1");
                //This works!!!
                t.html('Test');

                //Passing the element as the el, never works
                var table = new TableView({el : t});
            });
        </script>

Except it always says in the console: U ncaught TypeError: Object #<HTMLDivElement> has no method 'html' . Am I doing something wrong here? I'm using Jquery.1.7.2, backbone 0.9.2, underscore 1.3.3 and json2.

this.el is an element not a jQuery object. Try $(this.el).html() or this.$el.html()

它应该是

var table = new TableView({el : "#table_1"});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM