2013-12-09 17 views
2

沒有爲使用與Ember使用組件對話框官方食譜: http://emberjs.com/guides/cookbook/user_interface_and_interaction/using_modal_dialogs/如何簡單地將引導程序2模式對話框包裝在一個ember組件中?

我希望做的是使用Twitter的引導2個對話框來代替。

它可以工作,closeModal操作除外。

我需要註冊回調引導事件「隱藏」,調用關閉操作,但我的嘗試不成功。

App.ModalDialogComponent = Ember.Component.extend({ 
    didInsertElement: function() { 
     this.$('.modal').modal('show'); 
     this.$('.modal').on("hidden", function() { 
      // how to trigger the close action from here ? 
     }); 
    }, 
    actions: { 
     close: function() { 
      return this.sendAction(); 
     } 
    } 
}); 

這裏是一個完整的jsfiddle: http://jsfiddle.net/NQKvy/417/

回答

2

密切的行動是沒有必要的。

這裏是一個工作的jsfiddle,我只保留必要的部分,並添加willDestroyElement到組件: http://jsfiddle.net/NQKvy/421/

App.ModalDialogComponent = Ember.Component.extend({ 
    didInsertElement: function() { 
     var self = this; 
     this.$('.modal').modal('show'); 
     this.$('.modal').on("hidden", function() { 
      self.sendAction(); 
     }); 
    } 
}); 
1

做以下

App.ModalDialogComponent = Ember.Component.extend({ 
    didInsertElement: function() { 
     self=this 
     this.$('.modal').modal('show'); 
     this.$('.modal').on("hidden", function() { 
      self.send('close') 
     }); 
    }, 
    actions: { 
     close: function() { 
      return this.sendAction(); 
     } 
    } 
}); 
+0

謝謝,我確信那是我第一次嘗試(self.send的調用(「親密'))!但是我必須做一些其他的事情。無論如何,我在另一個迴應中加入了我正在使用的解決方案,以供參考。如果你閱讀這個問題,一定要看看它。 –

相關問題