子视图中的主干JS事件未触发

时间:2019-07-02 10:46:00

标签: backbone.js

对于该问题,我已经完成了大多数解决方案,但仍然无法解决。请帮助我。 。 无论我如何配置,我的子事件都不会触发,请指导我进行操作。 我的父母是'dayInfo',我从父母那里叫'schedule'。 但是html按钮不会触发事件。

///// schedule.html /////

<a class="ic-plus-circle add"></a>

///// schedule.js /////

define(function(require) {

var Backbone        = require('backbone'),
    User            = require('models/User'),
    css             = require('text!views/dayInfo/schedule.css'),
    tpl             = require('text!views/dayInfo/schedule.html');

return Backbone.View.extend({

    initialize: function(options) {

        this.template       = _.template(tpl);

        var self = this;

        return this;
    },

    render: function() {
        var self = this;

    self.$el.html(self.template());

        return this;
    },

    events: {

        'tap .add': function(e) {
            console.log('success');
            var self = this;
            var $this = $(e.currentTarget);

            console.log('tapped');                  
        }
    }
});
});

////// dayInfo.html /////

<div class="tab-content"></div>

/////// dayInfo.js /////

define(function(require) {

var Backbone        = require('backbone'),
    ScheduleView    = require('views/dayInfo/schedule'),
    css             = require('text!views/dayInfo/dayInfo.css'),
    tpl             = require('text!views/dayInfo/dayInfo.html');

return Backbone.View.extend({

    id : 'dayInfo',

    initialize: function(options) {
        this.template               = _.template(tpl);

        var self = this;

        return this;
    },

    render: function() {
        var self = this;

        self.$el.html(self.template());

        self.$tabContent = self.$el.find('.tab-content');

        self.scheduleView = new ScheduleView({date:self.date,doctor:self.doctor,appointments:self.appointments,events:self.events}).render();
        self.$tabContent.html(self.scheduleView.$el);
    }
});
});

我希望每当我单击按钮时,控制台都将“敲击”

1 个答案:

答案 0 :(得分:0)

没有tap事件,这就是为什么它不触发的原因。有关可用触摸事件的列表,请参见MDN - Touch events

您需要获取一个可与jQuery配合使用的触摸事件插件,以拥有自定义事件,例如tap