繁体   English   中英

Backbone.js查看不呈现EL

[英]Backbone.js View not rendering EL

我遇到了Backbone.js View无法渲染的问题。 我的代码非常简单,看起来像这样:

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: {

    },
});

这是用于实例化对象和设置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>

除了它总是在控制台中说:U ncaught TypeError: Object #<HTMLDivElement> has no method 'html' . 我在这里做错了吗? 我使用的是Jquery.1.7.2,主干0.9.2,下划线1.3.3和json2。

this.el是一个元素而不是jQuery对象。 试试$(this.el).html()或者this.$el.html()

它应该是

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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