2
 <!DOCTYPE HTML>
    <html>
    <head>
    <title></title>

    </head>
    <body>

    <div id="menu"></div>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script> 
        <script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js" type="text/javascript"></script>
        <script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js" type="text/javascript"></script>
        <script src="http://cdnjs.cloudflare.com/ajax/libs/backbone-localstorage.js/1.0/backbone.localStorage-min.js" type="text/javascript"></script>  

    <script type="text/javascript">
    var myView = Backbone.View.extend({
        events: {
            'click #menu': 'insideMenuHandler'
        },
    //for event click
        initialize: function() {
            _.bindAll(this, 'insideMenuHandler', 'outsideMenuHandler');
        },

        render: function() {
            // Both <body> and <html> for paranoia.
            $('body, html').on('click', this.outsideMenuHandler);
            // ...
            return this;
        },

        remove: function() {
            // Clean up after ourselves.
            $('body, html').off('click', this.outsideMenuHandler);
            // ...
        },

        // ...
        outsideMenuHandler: function(e) {
            // ...
            return false;
        }
    });

    var v=new myView({el: '#view-goes-here'});
    v.render();

    </script>
    </body>
    </html>

嘿,我是backbone.js 的新手,不明白下面的代码有什么问题,我在哪里更改我的代码以使其正常工作?是绑定函数有问题还是有其他问题?

4

1 回答 1

5

您正在_.bindAll排队等候

 _.bindAll(this, 'insideMenuHandler', 'outsideMenuHandler');

但是您insideMenuHandlerview.

于 2013-03-15T09:44:11.270 回答