简体   繁体   English

了解Backbone和Express中的点击事件

[英]Understanding click events in Backbone and Express

I am trying to learn some javascript and I've gone through several tutorials, now I'm trying to understand a real-life system. 我正在尝试学习一些JavaScript,并且已经阅读了一些教程,现在我试图了解一个真实的系统。 Here is a demo site that has been pretty well put together: 这是一个演示站点,已经很好地组合在一起:

http://nodecellar.coenraets.org/ http://nodecellar.coenraets.org/

https://github.com/ccoenraets/nodecellar https://github.com/ccoenraets/nodecellar

I think I understand the basics of how events can be assigned to elements on the page but then when I look through his source code I can't figure out how even the first click works. 我想我了解如何将事件分配给页面上的元素的基础知识,但是当我查看他的源代码时,即使是单击一下,我也无法弄清楚。 When you click "Start Browsing" it should be caught by javascript somehow which fires off an asynchronous request and triggers the view to change with the data received. 当您单击“开始浏览”时,JavaScript应该会以某种方式捕获它,从而触发异步请求并触发视图随接收到的数据而更改。 But in his / public/js/views/ nowhere is there event catching plugged in (except in the itemdetail view but that's a different view entirely). 但是在他的/ public / js / views /中没有插入事件捕获功能(itemdetail视图中除外,但这是完全不同的视图)。

I also tried using chrome developer tools to catch the click and find out what script caught it. 我还尝试使用chrome开发人员工具来捕获点击并找出捕获该点击的脚本。

  • Under sources I tried setting an event breakpoint for DOM mutation and then clicked.... but no breakpoint (how is that possible? There's definitely a DOM mutation happening) 在源下,我尝试为DOM突变设置事件断点,然后单击....但没有断点(这怎么可能?肯定发生了DOM突变)

  • I then went under elements and checked under the "click" event listener and didn't see anything revealing there either. 然后,我进入了元素之下,并在“ click”事件侦听器下进行了检查,并且那里也没有发现任何东西。

Obviously I don't know what I'm doing here. 显然我不知道我在这里做什么。 Can anyone help point me in the right direction? 谁能帮助我指出正确的方向?

This app is using backbones routing capabilities to switch contexts. 此应用程序使用骨干网路由功能来切换上下文。

It is basically using hash tags and listening for location change events to trigger updates to the page. 它基本上是使用哈希标签并侦听位置更改事件来触发页面更新。

The routing configuration is in main.js: 路由配置位于main.js中:

See: Backbone.Router for more information. 请参阅: Backbone.Router了解更多信息。

Code Reference: http://nodecellar.coenraets.org/#wines 代码参考: http : //nodecellar.coenraets.org/#wines

var AppRouter = Backbone.Router.extend({

    routes: {
        ""                  : "home",
        "wines" : "list",
        "wines/page/:page"  : "list",
        "wines/add"         : "addWine",
        "wines/:id"         : "wineDetails",
        "about"             : "about"
    },

    initialize: function () {
        this.headerView = new HeaderView();
        $('.header').html(this.headerView.el);
    },

    home: function (id) {
        if (!this.homeView) {
            this.homeView = new HomeView();
        }
        $('#content').html(this.homeView.el);
        this.headerView.selectMenuItem('home-menu');
    },

    list: function(page) {
        var p = page ? parseInt(page, 10) : 1;
        var wineList = new WineCollection();
        wineList.fetch({success: function(){
            $("#content").html(new WineListView({model: wineList, page: p}).el);
        }});
        this.headerView.selectMenuItem('home-menu');
    },

    // etc...

});

utils.loadTemplate(['HomeView', 'HeaderView', 'WineView', 'WineListItemView', 'AboutView'], function() {
    app = new AppRouter();
    Backbone.history.start();
});

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

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