1

我看到了一些例子,但我很困惑如何实现这个,有人可以给我一些帮助吗?我在 index.html 文件和主页视图上有一个 div 类,单击它会删除所有具有相应类的 div。我正在尝试在 .pageAlert div 点击的 bindRemoveAlert() 函数中设置它。

我收到这样的路由器模块超时错误:

路由器:

// Filename: router.js

define([
  'jquery',
  'jquery-ui',
  'underscore',
  'backbone',
    'bootstrap',
    'lightbox',
    'scripts',
  'views/home/HomeView',
  'views/schedule/ScheduleView',
  'views/patient/PatientView',
    'views/login/LoginView'
], function($, jui, _, Backbone, Bootstrap, lightbox, scripts, HomeView, ScheduleView,     PatientView, LoginView) {

  var AppRouter = Backbone.Router.extend({
routes: {
        'schedule': 'showSchedule',
  'patients': 'showPatients',
        'login':'showLogin',
  '*actions': 'defaultAction'
}
  });

var bindRemoveAlert = function() {
    vent = _.extend({}, Backbone.Events);
    vent.on("click .pageAlert div:", function(){
      console.log("some event was fired");
    });

    vent.trigger("click .pageAlert div:removeAlert");
}

var removeAlert = function(e) {
    var _this = this;
    // ajax to remove alert
    // success
    var alertData = $(e.currentTarget).parent().data('alert');
    console.log(alertData);
    $('.pageAlert-' + alertData).remove();
    var alertsNum = $('.pageAlert').length;
    $('#navAlerts span span').html(alertsNum);
    if(alertsNum == 0) {
        _this.$('#alerts').fadeOut(250);
        $('#navAlerts span').fadeOut(250);
    }
}

  var initialize = function() {

var app_router = new AppRouter;

el: $("#page"),

app_router.on('route:showSchedule', function (actions) {
    var scheduleView = new ScheduleView();
    scheduleView.render();
    $('#topBar').show();
            $('#navBar').show();
});

app_router.on('route:showPatients', function (actions) {
    var patientView = new PatientView();
    patientView.render();
    $('#topBar').show();
            $('#navBar').show();
});

    app_router.on('route:showLogin', function (actions) {
    var loginView = new LoginView();
    loginView.render();
            loginView.animateLogin();
            $('#topBar').hide();
            $('#navBar').hide();
});

app_router.on('route:defaultAction', function (actions) {
    var homeView = new HomeView();
    homeView.render();
    $('#topBar').show();
            $('#navBar').show();
});

    bindPatientSearch();

    bindRemoveAlert();

Backbone.history.start();

  };
  return { 
    initialize: initialize
  };

});
4

0 回答 0