0

刚从这里开始,似乎无法让这个非常基本的东西发挥作用。我所有的元素都按照我的预期呈现。我的事件在“事件”选项卡中的 Firefox 中注册,但似乎都没有触发(单击、鼠标悬停等)。我正在使用以下内容。

  • 骨干网 0.9.2
  • 下划线 1.4.1
  • 木偶 .10.2
  • 需要 jquery (requireJs 2.1.0) (jquery 1.8.2)

路由器

define([
'jquery',
'backbone',
'underscore',
'views/TodaysProgramsView',
'collections/ProgramSnippetCollection'],
function($, Backbone, _, TodaysProgramsView, ProgramSnippetCollection){
    return Backbone.Router.extend({
        initialize:function () {

            var programSnippetCollection = new ProgramSnippetCollection([
                {title:'underwater basket weaving'},
                {title:'How to win friends and influence people and stuff'}
            ]);

            this.mainView = new TodaysProgramsView({
                el : $("#todays_programs"),
                collection:programSnippetCollection
            });

            Backbone.history.start();
        },
        routes:{
            '':'home'
        },
        'home':function () {
            this.mainView.render();
        }
    });
});

集合视图 [TodaysProgramsView.js]

define([
'jquery',
'backbone',
'underscore',
'views/ProgramSnippetView'],
function($, Backbone, _, ProgramSnippetView){
    return  Backbone.Marionette.CollectionView.extend({

        events: {
            "click"   : "clicked"

        },
        clicked : function(){
            alert("parent clicked")
        },

       itemView : ProgramSnippetView
    });
});

项目视图 [ProgramSnippetView.js]

define([
'jquery',
'backbone',
'underscore',
'text!templates/programSnippet.html'],
function($, Backbone, _, template){
    return Backbone.Marionette.ItemView.extend({


        events: {
            "click"   : "courseClicked",
            'mouseover' : 'mousedOver'
        },

        render: function(){

            var json = this.model.toJSON();
            console.log("RENDERING SNIPPET with data", json);
            $(this.el).html( _.template(template, json) );
            return this;
        },

        courseClicked : function(){
            alert("you clicked a course, good work");
        },

        mousedOver : function(){
            console.log("Mousin!");
        }
    });


});
4

1 回答 1

0

在经历了很多挫折和数小时的 javascript 调整之后,我注意到有一个 div 的 z-index 设置为 2。这覆盖了我的目标并吞噬了所有事件。叹。

于 2012-10-08T16:56:43.113 回答