Backbone表单提交刷新Chrome中的页面

时间:2014-07-16 15:31:31

标签: javascript jquery twitter-bootstrap backbone.js

与此类似的问题:Browser page keeps refreshing when testing Backbone views with Jasmine。 提交我的Bootstrap-modal表单失败并刷新Chrome中的页面。我理解链接中找到的解决方案,但我不知道如何使其适用于Bootstrap表单。有什么帮助吗?

window.FormPopup = Backbone.View.extend({
template: _.template($('#popup-template').html()),

events: {
    "click .sector-label" : "edit",
    "keypress .sector-label-edit input" : "setLabel"
},

render: function() {
    var view = this;

    this.$el.html(this.template(this.model.toJSON()));
    this.$el.modal({
        backdrop: false
    });
    this.$el.on("hidden", function() {
        view.remove();
    });

    this.$el.find("form").submit(function() {
        $(this).find("input:text").each(function() {
            var label = $(this).val();
            if (label.length > 0)
                view.model.addChild(label);
        });
        view.$el.modal("hide");
    });
},

edit: function() {
    this.$el.addClass("edit");
    this.$el.find(".sector-label-edit input").focus();
},

setLabel: function(e) {
    if (e.keyCode != 13)
        return;
    var newLabel = this.$el.find(".sector-label-edit input").val();
    this.model.set("label", newLabel);
    this.$el.find(".sector-label h3").html(newLabel);
    this.$el.removeClass("edit");
},
});

0 个答案:

没有答案