簡體   English   中英

如何在余燼視圖中綁定到引導程序的模式事件?

[英]How do I bind to bootstrap's modal events in my ember view?

我正在使用余燼視圖來呈現我的應用程序的模式簡介,當前看起來像這樣:

意見/ modal.js

App.ModalView = Ember.View.extend({
    tagName: 'div',
    classNames: ['modal', 'fade'],
    templateName: 'modal',
    didInsertElement: function() {
        this.$().modal('show');
    }
});

控制器/的application.js

App.ApplicationController = Ember.ArrayController.extend({
    showModal: function() {
        var modal = App.ModalView.create();
        modal.append();
    }
});

modal.hbs模板只是一些樣板html。

當我觸發showModal函數時,我可以顯示模態很好,但是模態關閉后,我無法從DOM中刪除視圖,我試圖綁定到hidden事件,但我不知道如何,誰能指出我正確的方向?

我在現有應用中使用了這種方法,效果很好

App.ModalView = Ember.View.extend({
    templateName: "modal",
    title: "",
    content: "",
    classNames: ["modal", "fade", "hide"],
    didInsertElement: function() {
        this.$().modal("show");
        this.$().one("hidden", this._viewDidHide);
    },
    // modal dismissed by example clicked in X, make sure the modal view is destroyed
    _viewDidHide: function() {
        if (!this.isDestroyed) {
            this.destroy();
        }
    },
    // here we click in close button so _viewDidHide is called
    close: function() {        
        this.$(".close").click();
    }
});

在這里,我們偵聽hidden事件,該事件在模態完全隱藏時觸發,以銷毀對象。 這很重要,因為不會破壞以編程方式創建的調用view.append()視圖。 這種方法確保了這一點。

這是帶有示例的jsfiddle

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM